int[][] points_unaligned = new int[size][1];
grid.points_unaligned = points_unaligned;
- grid.points_index = CACHE_LINE_SIZE; // not sure it is right..
+ grid.points_index = CACHE_LINE_SIZE-2; // not sure it is right..
for(int i=grid.points_index;i<n;i++)
grid.points_unaligned[i][0] = GRID_POINT_EMPTY;
(srcGridPtr.height == dstGridPtr.height) ||
(srcGridPtr.depth == dstGridPtr.depth))
{
- System.out.println("Assert in Grid_Copy");
- System.out.exit(1);
- }
-
-
-
int n = srcGridPtr.width * srcGridPtr.height * srcGridPtr.depth;
for(int i=0;i<n;i++)
- dstGridPtr.points_unaligned[dstGridPtr.points_index + i][0] = srcGridPtr.points_unaligned[srcGridPtr.points_index + i][0];
+ dstGridPtr.points_unaligned[dstGridPtr.points_index + i][0] =
+ srcGridPtr.points_unaligned[srcGridPtr.points_index + i][0];
+ }
}
int x = coordinatePtr.x;
int y = coordinatePtr.y;
int z = coordinatePtr.z;
+
+// System.out.println("x = " + x + " y = " + y + " z = " + z);
setPoint(x,y,z,GRID_POINT_FULL);
}
}
-
+
+ public void TM_addPath(Vector_t pointVectorPtr)
+ {
+ int i;
+ int n = pointVectorPtr.vector_getSize();
+
+ for(i = 0; i < n; i++) {
+ int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
+
+ setPoint(gridPointIndex,GRID_POINT_FULL);
+ }
+ }
/* =============================================================================
* TMgrid_addPath
Maze mazePtr = Maze.alloc();
int numPathToRoute = mazePtr.readMaze(labyrinth.global_inputFile);
-
+
Router routerPtr = Router.alloc(labyrinth.xCost,labyrinth.yCost,
labyrinth.zCost,labyrinth.bendCost);
Solve_Arg routerArg = new Solve_Arg(routerPtr,mazePtr,pathVectorListPtr);
/* Create and start thread */
+
Labyrinth[] lb = new Labyrinth[labyrinth.numThread];
for(int i = 1; i<labyrinth.numThread;i++) {
lb[i] = new Labyrinth(i,routerArg);
}
+ long start = System.currentTimeMillis();
+
for(int i = 1; i<labyrinth.numThread;i++) {
lb[i].start();
}
+ Barrier.enterBarrier();
+ Router.solve(routerArg);
+ Barrier.enterBarrier();
+
/* End of Solve */
+ long finish = System.currentTimeMillis();
+
int numPathRouted = 0;
List_Iter it = new List_Iter();
numPathRouted += pathVectorPtr.vector_getSize();
}
+ float elapsed = ((float)finish-(float)start)/1000;
+
System.out.println("Paths routed = " + numPathRouted);
+ System.out.println("Elapsed time = " + elapsed);
boolean stats = mazePtr.checkPaths(pathVectorListPtr,labyrinth.global_doPrint);
if(!stats)
public Object next(List_t listPtr)
{
itPtr = itPtr.nextPtr;
+ return itPtr.dataPtr;
}
}
isParseError = true;
}
}else if(code.equals("p")) { /* paths (format: p x1 y1 z1 x2 y2 z2) */
- System.out.println("You there??");
if(numToken != 7) {
isParseError = true;
}
else {
Coordinate srcPtr = Coordinate.alloc(xy[0],xy[1],xy[2]);
Coordinate dstPtr = Coordinate.alloc(xy[3],xy[4],xy[5]);
-
+
if(Coordinate.isEqual(srcPtr,dstPtr)) {
isParseError = true;
}
else {
Pair coordinatePairPtr = Pair.alloc(srcPtr,dstPtr);
- boolean status = workListPtr.insert((Object)coordinatePairPtr);
- if(!status)
+ boolean status = workListPtr.insert(coordinatePairPtr);
+ if(!status) {
System.out.println("LIST_INSERT????");
+ System.exit(1);
+ }
+ srcVectorPtr.vector_pushBack(srcPtr);
+ dstVectorPtr.vector_pushBack(dstPtr);
+
}
}
}else if(code.equals("w")) {
*/
List_Iter it = new List_Iter();
it.reset(workListPtr);
-
while(it.hasNext(workListPtr)) {
Pair coordinatePairPtr = (Pair)it.next(workListPtr);
-
- workQueuePtr.queue_push((Object)coordinatePairPtr);
+ workQueuePtr.queue_push(coordinatePairPtr);
}
+
List_t.free(workListPtr);
return srcVectorPtr.vector_getSize();
/* Mark sources */
int numSrc = srcVectorPtr.vector_getSize();
+// System.out.println("numSrc = " +numSrc);
+// System.exit(1);
for(i = 0; i < numSrc; i++) {
Coordinate srcPtr = (Coordinate)srcVectorPtr.vector_at(i);
testGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
testGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,0);
}
+// testGridPtr.print();
+
/* Make sure path is contiguous and does not overlap */
int id = 0;
List_Iter it = new List_Iter();
int[] y = new int[1];
int[] z = new int[1];
gridPtr.getPointIndices(prevGridPointIndex,x,y,z);
+
if(testGridPtr.getPoint(x[0],y[0],z[0]) != 0) {
Grid.free(testGridPtr);
return false;
prevCoordinate.y = y[0];
prevCoordinate.z = z[0];
+
int numPoint = pointVectorPtr.vector_getSize();
int j;
+
for(j = 1; j< (numPoint - 1) ;j++) { /* no need to check endpoints */
int currGridPointIndex = ((Integer)pointVectorPtr.vector_at(j)).intValue();
Coordinate currCoordinate = new Coordinate();
currCoordinate.y = y[0];
currCoordinate.z = z[0];
- if(Coordinate.areAdjacent(currCoordinate,prevCoordinate)) {
+ if(!Coordinate.areAdjacent(currCoordinate,prevCoordinate)) {
+ System.out.println("you there?");
Grid.free(testGridPtr);
return false;
}
--- /dev/null
+/* =============================================================================
+ *
+ * queue.java
+ *
+ * =============================================================================
+ *
+ * Copyright (C) Stanford University, 2006. All Rights Reserved.
+ * Author: Chi Cao Minh
+ *
+ * Ported to Java
+ * Author:Alokika Dash
+ * University of California, Irvine
+ *
+ * =============================================================================
+ *
+ * Unless otherwise noted, the following license applies to STAMP files:
+ *
+ * Copyright (c) 2007, Stanford University
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Stanford University nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * =============================================================================
+ */
+
+#define QUEUE_GROWTH_FACTOR 2
+
+public class Queue_t {
+ int pop; /* points before element to pop */
+ int push;
+ int capacity;
+ Object[] elements;
+
+ public Queue_t() {
+ }
+
+ /* =============================================================================
+ * queue_alloc
+ * =============================================================================
+ */
+ public static Queue_t queue_alloc (int initCapacity)
+ {
+ Queue_t queuePtr = new Queue_t();
+
+ int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+ queuePtr.elements = new Object[capacity];
+ if (queuePtr.elements == null) {
+ queuePtr = null;
+ return null;
+ }
+ queuePtr.pop = capacity - 1;
+ queuePtr.push = 0;
+ queuePtr.capacity = capacity;
+
+ return queuePtr;
+ }
+
+
+ /* =============================================================================
+ * Pqueue_alloc
+ * =============================================================================
+ */
+ public Queue_t
+ Pqueue_alloc (int initCapacity)
+ {
+ Queue_t queuePtr = new Queue_t();
+
+ int capacity = ((initCapacity < 2) ? 2 : initCapacity);
+ queuePtr.elements = new Object[capacity];
+ if (queuePtr.elements == null) {
+ queuePtr = null;
+ return null;
+ }
+ queuePtr.pop = capacity - 1;
+ queuePtr.push = 0;
+ queuePtr.capacity = capacity;
+
+ return queuePtr;
+ }
+
+ /* =============================================================================
+ * queue_free
+ * =============================================================================
+ */
+ public void
+ queue_free (Queue_t queuePtr)
+ {
+ queuePtr.elements = null;
+ queuePtr = null;
+ }
+
+
+ /* =============================================================================
+ * Pqueue_free
+ * =============================================================================
+ */
+ public void
+ Pqueue_free (Queue_t queuePtr)
+ {
+ queuePtr.elements = null;
+ queuePtr = null;
+ }
+
+
+ /* =============================================================================
+ * TMqueue_free
+ * =============================================================================
+ *
+ public void
+ TMqueue_free (TM_ARGDECL Queue* queuePtr)
+ {
+ queuePtr.elements = null;
+ queuePtr = null;
+ }
+
+*/
+ /* =============================================================================
+ * queue_isEmpty
+ * =============================================================================
+ */
+ public boolean
+ queue_isEmpty ()
+ {
+ //int pop = queuePtr.pop;
+ //int push = queuePtr.push;
+ //int capacity = queuePtr.capacity;
+
+ return (((pop + 1) % capacity == push) ? true : false);
+ }
+
+
+ /* =============================================================================
+ * queue_clear
+ * =============================================================================
+ */
+ public void
+ queue_clear ()
+ {
+ pop = capacity - 1;
+ push = 0;
+ }
+
+
+ /* =============================================================================
+ * TMqueue_isEmpty
+ * =============================================================================
+ */
+
+
+
+ /* =============================================================================
+ * queue_push
+ * =============================================================================
+ */
+ public boolean
+ queue_push (Object dataPtr)
+ {
+
+ if(pop == push) {
+
+ System.out.println("push == pop in Queue.java");
+ return false;
+ }
+
+
+ /* Need to resize */
+ int newPush = (push + 1) % capacity;
+ if (newPush == pop) {
+
+ int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+ Object[] newElements = new Object[newCapacity];
+ if (newElements == null) {
+ return false;
+ }
+
+ int dst = 0;
+ Object[] tmpelements = elements;
+ if (pop < push) {
+ int src;
+ for (src = (pop + 1); src < push; src++, dst++) {
+ newElements[dst] = elements[src];
+ }
+ } else {
+ int src;
+ for (src = (pop + 1); src < capacity; src++, dst++) {
+ newElements[dst] = elements[src];
+ }
+ for (src = 0; src < push; src++, dst++) {
+ newElements[dst] = elements[src];
+ }
+ }
+
+ //elements = null;
+ elements = newElements;
+ pop = newCapacity - 1;
+ capacity = newCapacity;
+ push = dst;
+ newPush = push + 1; /* no need modulo */
+ }
+
+ elements[push] = dataPtr;
+ push = newPush;
+
+ return true;
+ }
+
+
+ /* =============================================================================
+ * Pqueue_push
+ * =============================================================================
+ */
+ public boolean
+ Pqueue_push (Queue_t queuePtr, Object dataPtr)
+ {
+ int pop = queuePtr.pop;
+ int push = queuePtr.push;
+ int capacity = queuePtr.capacity;
+
+ if(pop == push) {
+ System.out.println("push == pop in Queue.java");
+ return false;
+ }
+
+ /* Need to resize */
+ int newPush = (push + 1) % capacity;
+ if (newPush == pop) {
+
+ int newCapacity = capacity * QUEUE_GROWTH_FACTOR;
+ Object[] newElements = new Object[newCapacity];
+ if (newElements == null) {
+ return false;
+ }
+
+ int dst = 0;
+ Object[] elements = queuePtr.elements;
+ if (pop < push) {
+ int src;
+ for (src = (pop + 1); src < push; src++, dst++) {
+ newElements[dst] = elements[src];
+ }
+ } else {
+ int src;
+ for (src = (pop + 1); src < capacity; src++, dst++) {
+ newElements[dst] = elements[src];
+ }
+ for (src = 0; src < push; src++, dst++) {
+ newElements[dst] = elements[src];
+ }
+ }
+
+ elements = null;
+ queuePtr.elements = newElements;
+ queuePtr.pop = newCapacity - 1;
+ queuePtr.capacity = newCapacity;
+ push = dst;
+ newPush = push + 1; /* no need modulo */
+
+ }
+
+ queuePtr.elements[push] = dataPtr;
+ queuePtr.push = newPush;
+
+ return true;
+ }
+
+ /* =============================================================================
+ * queue_pop
+ * =============================================================================
+ */
+ public Object
+ //queue_pop (Queue queuePtr)
+ queue_pop ()
+ {
+ //int pop = queuePtr.pop;
+ //int push = queuePtr.push;
+ //int capacity = queuePtr.capacity;
+
+ int newPop = (pop + 1) % capacity;
+ if (newPop == push) {
+ return null;
+ }
+
+ //Object dataPtr = queuePtr.elements[newPop];
+ //queuePtr.pop = newPop;
+ Object dataPtr = elements[newPop];
+ pop = newPop;
+
+ return dataPtr;
+ }
+
+
+}
+/* =============================================================================
+ *
+ * End of queue.java
+ *
+ * =============================================================================
+ */
{
if (myGridPtr.isPointValid(x,y,z)) {
int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z);
- int neighborValue = myGridPtr.getPoint(neighborGridPointIndex);
+ int neighborValue = myGridPtr.points_unaligned[neighborGridPointIndex][0];
if (neighborValue == GRID_POINT_EMPTY) {
myGridPtr.setPoint(neighborGridPointIndex,value);
queuePtr.queue_push(new Integer(neighborGridPointIndex));
int yCost = routerPtr.yCost;
int zCost = routerPtr.zCost;
-
/*
* Potential Optimization: Make 'src' the one closet to edge.
* This will likely decrease the area of the emitted wave.
queuePtr.queue_clear();
int srcGridPointIndex = myGridPtr.getPointIndex(srcPtr.x,srcPtr.y,srcPtr.z);
+
queuePtr.queue_push(new Integer(srcGridPointIndex));
+ // System.out.println("dstPtr :\tx = " + dstPtr.x + "\ty = " + dstPtr.y + "\tz = " + dstPtr.z);
myGridPtr.setPoint(srcPtr.x,srcPtr.y,srcPtr.z,0);
myGridPtr.setPoint(dstPtr.x,dstPtr.y,dstPtr.z,GRID_POINT_EMPTY);
int dstGridPointIndex = myGridPtr.getPointIndex(dstPtr.x,dstPtr.y,dstPtr.z);
boolean isPathFound = false;
- while (queuePtr.queue_isEmpty()) {
+ while (!queuePtr.queue_isEmpty()) {
int gridPointIndex = ((Integer)queuePtr.queue_pop()).intValue();
+
+// System.out.println("gridPointIndex = " +gridPointIndex);
if(gridPointIndex == dstGridPointIndex) {
isPathFound = true;
break;
int[] z = new int[1];
myGridPtr.getPointIndices(gridPointIndex,x,y,z);
- int value = myGridPtr.getPoint(gridPointIndex);
+ int value = myGridPtr.points_unaligned[gridPointIndex][0];
/*
* Check 6 neighbors
*/
PexpandToNeighbor(myGridPtr, x[0]+1, y[0], z[0], (value + xCost), queuePtr);
PexpandToNeighbor(myGridPtr, x[0]-1, y[0], z[0], (value + xCost), queuePtr);
- PexpandToNeighbor(myGridPtr, x[0], y[0]+1, z[0], (value + xCost), queuePtr);
- PexpandToNeighbor(myGridPtr, x[0], y[0]-1, z[0], (value + xCost), queuePtr);
- PexpandToNeighbor(myGridPtr, x[0], y[0], z[0]+1, (value + xCost), queuePtr);
- PexpandToNeighbor(myGridPtr, x[0], y[0], z[0]-1, (value + xCost), queuePtr);
+ PexpandToNeighbor(myGridPtr, x[0], y[0]+1, z[0], (value + yCost), queuePtr);
+ PexpandToNeighbor(myGridPtr, x[0], y[0]-1, z[0], (value + yCost), queuePtr);
+ PexpandToNeighbor(myGridPtr, x[0], y[0], z[0]+1, (value + zCost), queuePtr);
+ PexpandToNeighbor(myGridPtr, x[0], y[0], z[0]-1, (value + zCost), queuePtr);
} /* iterate over work queue */
if (next.value == 0) {
break;
}
- Point curr = next;
+ Point curr = new Point();
+ curr.x = next.x;
+ curr.y = next.y;
+ curr.z = next.z;
+ curr.value = next.value;
+ curr.momentum = next.momentum;
/*
* Check 6 neibors
traceToNeighbor(myGridPtr,curr,MOVE_POSX,true, bendCost, next);
traceToNeighbor(myGridPtr,curr,MOVE_POSY,true, bendCost, next);
traceToNeighbor(myGridPtr,curr,MOVE_POSZ,true, bendCost, next);
- traceToNeighbor(myGridPtr,curr,MOVE_NEGX,true, bendCost, next);
+ traceToNeighbor(myGridPtr,curr,MOVE_NEGX,true, bendCost, next);
traceToNeighbor(myGridPtr,curr,MOVE_NEGY,true, bendCost, next);
traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,true, bendCost, next);
* Because of bend costs, none of the neighbors may appear to be closer.
* In this case, pick a neighbor while ignoring momentum.
*/
+
+// System.out.println("next x = " + next.x + " y = " + next.y + " z = " + next.z);
if ((curr.x == next.y) &&
(curr.y == next.y) &&
(curr.z == next.z))
{
pointVectorPtr.vector_free();
+ System.out.println("Dead");
return null;
}
}
public static void solve(Object argPtr)
{
// TM_THREAD_ENTER();
+ //
Solve_Arg routerArgPtr = (Solve_Arg) argPtr;
Router routerPtr = routerArgPtr.routerPtr;
Maze mazePtr = routerArgPtr.mazePtr;
Coordinate srcPtr = (Coordinate)coordinatePairPtr.first;
Coordinate dstPtr = (Coordinate)coordinatePairPtr.second;
+
+// System.out.println("SRC x = " + srcPtr.x + " y = " + srcPtr.y + " z = " +srcPtr.z);
boolean success = false;
Vector_t pointVectorPtr = null;
+
// TM_BEGIN();
atomic {
Grid.copy(myGridPtr, gridPtr); /* ok if not most up-to-date */
pointVectorPtr = routerPtr.PdoTraceback(gridPtr,myGridPtr,dstPtr,bendCost);
if (pointVectorPtr != null) {
- gridPtr.addPath(pointVectorPtr);
+ gridPtr.TM_addPath(pointVectorPtr);
success = true;
}
+
}
}
if(success) {
boolean status = myPathVectorPtr.vector_pushBack(pointVectorPtr);
- if(status) {
- System.out.println("Error in Router_Solve");
+
+ if(!status) {
+ System.out.println("Assert in Router_Solve");
System.exit(1);
}
}
atomic {
pathVectorListPtr.insert(myPathVectorPtr);
}
+
+// System.out.println("Final Grid: ");
+// gridPtr.print();
// TM_THREAD_EXIT();
}
Solve_arg.java \
../../../ClassLibrary/JavaSTM/Barrier.java
-FLAGS=-mainclass ${MAINCLASS} -thread -nooptimize -debug
+FLAGS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -joptimize -fastmemcpy -profile
default:
cpp ${MAINCLASS}.java > tmp${MAINCLASS}.java