almost done with port
authorbdemsky <bdemsky>
Sun, 18 Oct 2009 06:02:25 +0000 (06:02 +0000)
committerbdemsky <bdemsky>
Sun, 18 Oct 2009 06:02:25 +0000 (06:02 +0000)
Robust/src/Benchmarks/SingleTM/Yada/Queue_t.java
Robust/src/Benchmarks/SingleTM/Yada/RBTree.java
Robust/src/Benchmarks/SingleTM/Yada/avltree.java
Robust/src/Benchmarks/SingleTM/Yada/element.java
Robust/src/Benchmarks/SingleTM/Yada/global.java [new file with mode: 0644]
Robust/src/Benchmarks/SingleTM/Yada/heap.java
Robust/src/Benchmarks/SingleTM/Yada/mesh.java
Robust/src/Benchmarks/SingleTM/Yada/region.java
Robust/src/Benchmarks/SingleTM/Yada/yada.java

index 901a4f297da55df4f5e7a9c9602fba9920544c5c..4173f96c2da5535099d5575adf2af1bd1b370722 100644 (file)
@@ -69,6 +69,9 @@ public class Queue_t {
     this.capacity = capacity;
   }
 
+
+
+
   /* =============================================================================
    * queue_isEmpty
    * =============================================================================
@@ -100,6 +103,27 @@ public class Queue_t {
    */
 
 
+  public void queue_shuffle(Random randomPtr) {
+    int numElement;
+    if (pop < push) {
+      numElement = push - (pop + 1);
+    } else {
+      numElement = capacity - (pop - push + 1);
+    }
+    
+    int base = pop + 1;
+    for (int i = 0; i < numElement; i++) {
+      int r1 = (int) randomPtr.random_generate() % numElement;
+      int r2 = (int) randomPtr.random_generate() % numElement;
+      int i1 = (base + r1) % capacity;
+      int i2 = (base + r2) % capacity;
+      Object tmp = elements[i1];
+      elements[i1] = elements[i2];
+      elements[i2] = tmp;
+    }
+  }
+
+
 
   /* =============================================================================
    * queue_push
index e63e4a2b4027ef1b8bdf4a5a8d2320517bd8e43b..aad71d3c66c934c59ce78547868c67ed86af28a3 100644 (file)
@@ -580,7 +580,7 @@ public class RBTree {
  * =============================================================================
  * bool_t rbtree_delete (rbtree_t* r, void* key);
  */
-  public boolean deleteNode(Object key)  {
+  public boolean deleteObjNode(Object key)  {
         Node node = null;
         node = lookup(key);
 
index 204b51e19789dca9e489ca375a9a2da589e030a1..cb69209c49c6b278d2187c7af416b0193f5b829c 100644 (file)
@@ -266,7 +266,7 @@ public class avltree {
     boolean success = false;
     edge searchPair=new edge();
     searchPair.firstPtr = key;
-    if (map.avlfind(map, searchPair) != null) {
+    if (avlfind(searchPair) != null) {
       success = true;
     }
     return success;
@@ -276,7 +276,7 @@ public class avltree {
     Object dataPtr = null;
     edge searchPair=new edge();
     searchPair.firstPtr = key;
-    edge pairPtr = (edge)map.avlfind(searchPair);
+    edge pairPtr = (edge)avlfind(searchPair);
     if (pairPtr != null) {
       dataPtr = pairPtr.secondPtr;
     }
@@ -286,10 +286,8 @@ public class avltree {
   boolean insert(Object key, Object data) {
     boolean success = false;
     edge insertPtr = new edge(key, data);
-    if (insertPtr != null) {
-      if (map.insert(insertPtr)) {
-       success = true;
-      }
+    if (avlinsert(insertPtr)) {
+      success = true;
     }
     return success;
   }
@@ -298,8 +296,8 @@ public class avltree {
     boolean success = false;
     edge searchPair=new edge();
     searchPair.firstPtr = key;
-    edge pairPtr = (edge) map.avlfind(searchPair);
-    if (map.avlerase(searchPair)) {
+    edge pairPtr = (edge) avlfind(searchPair);
+    if (avlerase(searchPair)) {
       success=true;
     }
     return success;
index 5057f7eb1aae8245db38748517b9da65721a7194..28ac04b2df9d69dc8993b78bd35d0203497400cb 100644 (file)
@@ -308,8 +308,8 @@ int element_compare (element aElementPtr, element bElementPtr) {
  * =============================================================================
  */
   int element_mapCompare(Object aPtr, Object bPtr) {
-    element aElementPtr = (element)(aPtr.firstPtr);
-    element bElementPtr = (element)(bPtr.firstPtr);
+    element aElementPtr = (element)(((edge)aPtr).firstPtr);
+    element bElementPtr = (element)(((edge)bPtr).firstPtr);
     
     return element_compare(aElementPtr, bElementPtr);
   }
diff --git a/Robust/src/Benchmarks/SingleTM/Yada/global.java b/Robust/src/Benchmarks/SingleTM/Yada/global.java
new file mode 100644 (file)
index 0000000..259ee69
--- /dev/null
@@ -0,0 +1,7 @@
+public global {
+  public global() {
+  }
+
+  int global_totalNumAdded;
+  int global_numProcess;
+}
\ No newline at end of file
index 5e00ce3b148781cbb8ee1576a6c6db940dac3351..a82fa543c2a8b8628a88b21a8fbb58e73b63bfe9 100644 (file)
@@ -93,8 +93,8 @@ public class heap {
  * siftUp
  * =============================================================================
  */
-  public void siftUp(long startIndex) {
-    long index = startIndex;
+  public void siftUp(int startIndex) {
+    int index = startIndex;
     while ((index > 1)) {
       long parentIndex = PARENT(index);
       Object parentPtr = elements[parentIndex];
index b7f4eda2951807c4c71e2063fb112897de067972..7b2682cc706571df904a9a39b6eda83ef7596842 100644 (file)
@@ -160,14 +160,16 @@ public void TMmesh_remove(element elementPtr) {
   /*
    * Remove from neighbors
    */
-  list_iter_t it;
+  
   List_t neighborListPtr = elementPtr.element_getNeighborListPtr();
-  TMLIST_ITER_RESET(it, neighborListPtr);
-  while (TMLIST_ITER_HASNEXT(it, neighborListPtr)) {
-      element neighborPtr = (element)TMLIST_ITER_NEXT(it, neighborListPtr);
-      List_t neighborNeighborListPtr = neighborPtr.element_getNeighborListPtr();
-      boolean status = neighborNeighborListPtr.remove(elementPtr);
-      yada.Assert(status);
+  List_Node it=neighborListPtr.head;
+
+  while (it.nextPtr!=null) {
+    it=it.nextPtr;
+    element neighborPtr = (element)it.dataPtr;
+    List_t neighborNeighborListPtr = neighborPtr.element_getNeighborListPtr();
+    boolean status = neighborNeighborListPtr.remove(elementPtr);
+    yada.Assert(status);
   }
 
   elementPtr.element_isGarbage(true);
@@ -349,7 +351,7 @@ int mesh_read(String fileNamePrefix) {
  * =============================================================================
  */
 element mesh_getBad() {
-  return (element)queue_pop(initBadQueuePtr);
+  return (element)initBadQueuePtr.queue_pop();
 }
 
 
@@ -358,7 +360,7 @@ element mesh_getBad() {
  * =============================================================================
  */
 void mesh_shuffleBad (Random randomPtr) {
-  queue_shuffle(initBadQueuePtr, randomPtr);
+  initBadQueuePtr.queue_shuffle(randomPtr);
 }
 
 
@@ -382,7 +384,6 @@ boolean mesh_check(int expectedNumElement) {
     yada.Assert(rootElementPtr!=null);
     searchQueuePtr.queue_push(rootElementPtr);
     while (!searchQueuePtr.queue_isEmpty()) {
-        list_iter_t it;
         List_t neighborListPtr;
 
         element currentElementPtr = (element)queue_pop(searchQueuePtr);
@@ -396,19 +397,20 @@ boolean mesh_check(int expectedNumElement) {
         }
         neighborListPtr = currentElementPtr.element_getNeighborListPtr();
 
-        list_iter_reset(it, neighborListPtr);
-        while (list_iter_hasNext(it, neighborListPtr)) {
-            element neighborElementPtr =
-                (element)list_iter_next(it, neighborListPtr);
-            /*
-             * Continue breadth-first search
-             */
-            if (!visitedMapPtr.contains(neighborElementPtr)) {
-                boolean isSuccess = searchQueuePtr.queue_push(neighborElementPtr);
-                yada.Assert(isSuccess);
-            }
+        List_Node it=neighborListPtr.head;
+        while (it.nextPtr!=null) {
+         it=it.nextPtr;
+         element neighborElementPtr =
+           (element)it.dataPtr;
+         /*
+          * Continue breadth-first search
+          */
+         if (!visitedMapPtr.contains(neighborElementPtr)) {
+           boolean isSuccess = searchQueuePtr.queue_push(neighborElementPtr);
+           yada.Assert(isSuccess);
+         }
         } /* for each neighbor */
-
+       
         numElement++;
 
     } /* breadth-first search */
index 54857bb13742bcfa44b10c013156c31aa5ccd0c5..2b432f784827362b514712b2b2b34da31a173081 100644 (file)
@@ -110,10 +110,9 @@ public class region {
     Vector_t badVectorPtr = regionPtr.badVectorPtr; /* private */
     List_t beforeListPtr = regionPtr.beforeListPtr; /* private */
     List_t borderListPtr = regionPtr.borderListPtr; /* private */
-    list_iter_t it;
     int numDelta = 0;
     
-    yada.Assert(edgeMapPtr);
+    yada.Assert(edgeMapPtr!=null);
     
     coordinate centerCoordinate = elementPtr.element_getNewPoint();
     
@@ -121,9 +120,11 @@ public class region {
      * Remove the old triangles
      */
     
-    list_iter_reset(it, beforeListPtr);
-    while (list_iter_hasNext(it, beforeListPtr)) {
-      element beforeElementPtr = (element)list_iter_next(it, beforeListPtr);
+    List_Node it=beforeListPtr.head;
+
+    while (it.nextPtr!=null) {
+      it=it.nextPtr;
+      element beforeElementPtr = (element)it.nodePtr;
       meshPtr.TMmesh_remove(beforeElementPtr);
     }
     
@@ -164,10 +165,10 @@ public class region {
      * point and the two points from the border segment.
      */
 
-    list_iter_reset(it, borderListPtr);
-    while (list_iter_hasNext(it, borderListPtr)) {
+    it=borderListPtr.head;
+    while (it.nextPtr!=null) {
       coordinate coordinates[]=new coordinates[3];
-      edge borderEdgePtr = (edge)list_iter_next(it, borderListPtr);
+      edge borderEdgePtr = (edge)it.dataPtr;
       yada.Assert(borderEdgePtr);
       coordinates[0] = centerCoordinate;
       coordinates[1] = (coordinate)(borderEdgePtr.firstPtr);
@@ -217,10 +218,10 @@ public class region {
       beforeListPtr.insert(currentElementPtr); /* no duplicates */
       List_t neighborListPtr = currentElementPtr.element_getNeighborListPtr();
       
-      list_iter_t it;
-      TMLIST_ITER_RESET(it, neighborListPtr);
-      while (TMLIST_ITER_HASNEXT(it, neighborListPtr)) {
-       element neighborElementPtr = (element)TMLIST_ITER_NEXT(it, neighborListPtr);
+      List_Node it=neighborListPtr.head;
+      while (it.nextPtr!=null) {
+       it=it.nextPtr;
+       element neighborElementPtr = (element)it.dataPtr;
        neighborElementPtr.element_isGarbage(); /* so we can detect conflicts */
        if (!beforeListPtr.find(neighborElementPtr)) {
          if (neighborElementPtr.element_isInCircumCircle(centerCoordinatePtr)) {
@@ -275,10 +276,9 @@ public class region {
       
       if (encroachElementPtr!=null) {
        encroachElementPtr.element_setIsReferenced(true);
-       numDelta += TMregion_refine(regionPtr,
-                                   encroachElementPtr,
+       numDelta += TMregion_refine(encroachElementPtr,
                                    meshPtr);
-       if (elementPtr.elementisGarbage()) {
+       if (elementPtr.element_isGarbage()) {
          break;
        }
       } else {
index 3c3563632d246d988d2d2a1ccbca88540b2fc134..0526517bb643ede838a00bbf3cb8953df991365d 100644 (file)
@@ -57,6 +57,7 @@ public class yada {
   heap  global_workHeapPtr;
   int global_totalNumAdded;
   int global_numProcess;
+  global global;
 
   public yada() {
     global_inputPrefix     = "";
@@ -66,6 +67,13 @@ public class yada {
     global_numProcess    = 0;
   }
 
+  public yada(mesh meshptr, heap heapptr, double angle, global g) {
+    global_meshPtr=meshptr;
+    global_workHeapPtr=heapptr;
+    global_angleConstraint=angle;
+    global=g;
+  }
+
 
 /* =============================================================================
  * displayUsage
@@ -129,15 +137,12 @@ public class yada {
   }
   
   public static void Assert(boolean status) {
-    
   }
 /* =============================================================================
  * process
  * =============================================================================
  */
   public static void process() {
-    TM_THREAD_ENTER();
-
     heap workHeapPtr = global_workHeapPtr;
     mesh meshPtr = global_meshPtr;
     int totalNumAdded = 0;
@@ -184,14 +189,17 @@ public class yada {
     }
 
     atomic {
-      global_totalNumAdded=global_totalNumAdded + totalNumAdded;
-      global_numProcess=global_numProcess + numProcess;
+      global.global_totalNumAdded=global.global_totalNumAdded + totalNumAdded;
+      global.global_numProcess=global.global_numProcess + numProcess;
     }
+  }
 
-    TM_THREAD_EXIT();
-}
-
-
+  public void run() {
+    Barrier.enterBarrier();
+    process()
+    Barrier.enterBarrier();
+  }
+  
 /* =============================================================================
  * main
  * =============================================================================
@@ -201,16 +209,23 @@ public class yada {
      * Initialization
      */
     yada y=new yada();
+    global g=new global();
+    y.global=g;
     y.parseArgs(argv);
-    thread_startup(global_numThread);
+    Barrier.setBarrier(y.global_numThread);
     y.global_meshPtr = new mesh();
-    System.out.println("Angle constraint = "+ global_angleConstraint);
+    System.out.println("Angle constraint = "+ y.global_angleConstraint);
     System.out.println("Reading input... ");
-    int initNumElement = global_meshPtr.mesh_read(global_inputPrefix);
+    int initNumElement = y.global_meshPtr.mesh_read(global_inputPrefix);
     System.out.println("done.");
     y.global_workHeapPtr = new heap(1);
 
-    int initNumBadElement = global_workHeapPtr.initializeWork(global_meshPtr);
+    for(int i=1;i<global_numThread;i++) {
+      yada ychild=new yada(y.global_meshPtr, y.global_angleConstraint, y.global_angleConstraint, g);
+      ychild.start();
+    }
+
+    int initNumBadElement = y.global_workHeapPtr.initializeWork(y.global_meshPtr);
 
     System.out.println("Initial number of mesh elements = "+ initNumElement);
     System.out.println("Initial number of bad elements  = "+ initNumBadElement);
@@ -221,17 +236,15 @@ public class yada {
      */
 
     long start=System.currentTimeMillis();
-
-    thread_start(process, null);
-
+    y.run();
     long stop=System.currentTimeMillis();
 
     System.out.println(" done.");
     System.out.println("Elapsed time                    = "+(stop-start));
 
-    int finalNumElement = initNumElement + global_totalNumAdded;
+    int finalNumElement = initNumElement + y.global.global_totalNumAdded;
     System.out.println("Final mesh size                 = "+ finalNumElement);
-    System.out.println("Number of elements processed    = "+ global_numProcess);
+    System.out.println("Number of elements processed    = "+ y.global.global_numProcess);
   }
 }