this.capacity = capacity;
}
+
+
+
/* =============================================================================
* queue_isEmpty
* =============================================================================
*/
+ 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
* =============================================================================
* 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);
boolean success = false;
edge searchPair=new edge();
searchPair.firstPtr = key;
- if (map.avlfind(map, searchPair) != null) {
+ if (avlfind(searchPair) != null) {
success = true;
}
return success;
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;
}
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;
}
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;
* =============================================================================
*/
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);
}
--- /dev/null
+public global {
+ public global() {
+ }
+
+ int global_totalNumAdded;
+ int global_numProcess;
+}
\ No newline at end of file
* 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];
/*
* 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);
* =============================================================================
*/
element mesh_getBad() {
- return (element)queue_pop(initBadQueuePtr);
+ return (element)initBadQueuePtr.queue_pop();
}
* =============================================================================
*/
void mesh_shuffleBad (Random randomPtr) {
- queue_shuffle(initBadQueuePtr, randomPtr);
+ initBadQueuePtr.queue_shuffle(randomPtr);
}
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);
}
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 */
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();
* 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);
}
* 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);
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)) {
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 {
heap global_workHeapPtr;
int global_totalNumAdded;
int global_numProcess;
+ global global;
public yada() {
global_inputPrefix = "";
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
}
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;
}
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
* =============================================================================
* 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);
*/
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);
}
}