From: jihoonl Date: Mon, 22 Jun 2009 23:36:31 +0000 (+0000) Subject: Labyrinth benchmakr X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7cae6939c67ddc9ccd592fdc8f696a2bf9af3237;p=IRC.git Labyrinth benchmakr --- diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/Coordinate.java b/Robust/src/Benchmarks/SingleTM/Labyrinth/Coordinate.java new file mode 100644 index 00000000..0aca62e6 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/Coordinate.java @@ -0,0 +1,176 @@ +/* ============================================================================= + * + * coordinate.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * 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. + * + * ============================================================================= + */ + + + + +import java.lang.Math; + +public class Coordinate { + + public int x; + public int y; + public int z; + + + // coordiate_alloc will be constructor + // coordinate_t* coordinate_alloc(long x, long y, long z) + public Coordinate(int x,int y,int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public static Coordinate alloc(int x,int y,int z) { + Coordinate c = new Coordinate(x,y,z); + + return c; + } + + + // deallocate memory + // may not need + // coordinate_free + + /*======================================================== + // coordinate_isEqual + ==========================================================*/ + public static boolean isEqual(Coordinate a,Coordinate b) + { + if((a.x == b.x) && (a.y == b.y) && (a.z == b.z)) + return true; + + return false; + } + + /*========================================================== + * + * getPairDistance + * + *========================================================*/ + private static double getPairDistance(Pair p) + { + Coordinate a = (Coordinate)p.a; + Coordinate b = (Coordinate)p.b; + int dx = a.x - b.x; + int dy = a.y - b.y; + int dz = a.z - b.z; + int dx2 = dx* dx; + int dy2 = dy* dy; + int dz2 = dz* dz; + + return Math.sqrt((double)(dx2+dy2+dz2)); + } + + + /*================================================ + // coordinat_ comparePair + * -- For sorting in list of source/destination pairs + * -- Route longer paths first so they are more likely to suceed + + *================================================*/ + public static int comparePair(final Object a,final Object b) + { + double aDistance = getPairDistance((Pair)a); + double bDistnace = getPairDistance((Pair)b); + + if(aDistance < bDistance) { + return 1; + } else if(aDistance > bDistance) { + return -1; + } + + return 0; + } + + /*======================================================= + * coordinate_areAdjacent + *=======================================================*/ + + public static boolean areAdjacent(Coordinate a,Coordinate b) + { + int dx = a.x - b.x; + int dy = a.y - b.y; + int dz = a.z - b.z; + int dx2 = dx * dx; + int dy2 = dy * dy; + int dz2 = dz * dz; + + return (((dx2 + dy2 + dz2) == 1) ? true : false); + } + } + + /*===================================================== + * + * End of Coordinate + * + *====================================================*/ + + diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/Grid.java b/Robust/src/Benchmarks/SingleTM/Labyrinth/Grid.java new file mode 100644 index 00000000..1d94d153 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/Grid.java @@ -0,0 +1,339 @@ +/* ============================================================================= + * + * grid.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * 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. + * + * ============================================================================= + */ + +import java.lang.Long; + +#define CACHE_LINE_SIZE 8 +#define GRID_POINT_FULL -2 +#define GRID_POINT_EMPTY -1 + +public class Grid { + public int width; + public int height; + public int depth; + public int points_index; + public int[][] points_unaligned; + + + +/* ============================================================================= + * grid_alloc + * ============================================================================= + grid_t* grid_alloc (long width, long height, long depth); + + well... need to implement + got stuck + */ + public static Grid alloc(int width,int height,int depth) { + Grid grid = new Grid(); + + if(grid) { + + grid.width = width; + grid.height = height; + grid.depth = depth; + + int n = width * height * depth; + + // long* points_unaligned = (long*) malloc(n*sizeof(long) + CACHE_LINE_SIZE); + int size = n + CACHE_LINE_SIZE; + int[][] points_unaligned = new int[size][1]; + + grid.points_unaligned = points_unaligned; + grid.points_index = CACHE_LINE_SIZE; // not sure it is right.. + + for(int i=grid.points_index;i= width || + y < 0 || y >= height || + z < 0 || z >= depth) + { + return false; + } + + return true; + } + + +/* ============================================================================= + * grid_getPointRef + * ============================================================================= +long* grid_getPointRef (grid_t* gridPtr, long x, long y, long z); + + it is returning the index of the point +*/ + public int getPointIndex(int x,int y,int z) + { + return points_index + (((z * height) + y) * width + x); + } + + +/* ============================================================================= + * grid_getPointIndices + * ============================================================================= + void grid_getPointIndices (grid_t* gridPtr, + long* gridPointPtr, long* xPtr, long* yPtr, long* zPtr); + */ + public void getPointIndices(int gridPointIndex,int[] xPtr, int[] yPtr,int[] zPtr) + { + int height = this.heigt; + int width = this.width; + int area = height * width; + int index3d = (gridPointIndex - this.points_index); + zPtr[0] = index3d / area; + long index2d = index3d % area; + yPtr[0] = index2d / width; + xPtr[0] = index2d % width; + } + + +/* ============================================================================= + * grid_getPoint + * ============================================================================= + long grid_getPoint (grid_t* gridPtr, long x, long y, long z); + */ + public int getPoint(int x,int y,int z) + { + return this.points_unaligned[getPointIndex(x,y,z)][0]; + } + + public int getPoint(int index) + { + return this.points_unaligned[index][0]; + } + + +/* ============================================================================= + * grid_isPointEmpty + * ============================================================================= + bool_t grid_isPointEmpty (grid_t* gridPtr, long x, long y, long z); + */ + public boolean isPointEmpty(int x,int y,int z) + { + int value = getPoint(x,y,z)[0]; + return ((value == GRID_POINT_EMPTY) ? true:false); + } + + + +/* ============================================================================= + * grid_isPointFull + * ============================================================================= + bool_t grid_isPointFull (grid_t* gridPtr, long x, long y, long z); + */ + public boolean isPointFull(int x,int y,int z) + { + int value = getPoint(x,y,z)[0]; + return ((value == GRID_POINT_FULL) ? true : false); + } + + +/* ============================================================================= + * grid_setPoint + * ============================================================================= + void grid_setPoint (grid_t* gridPtr, long x, long y, long z, long value); + */ + public void setPoint(int x,int y,int z,int value) + { + points_unaligned[getPointIndex(x,y,z)][0] = value; + } + + public void setPoint(int index,int value) + { + points_unaligned[index][0] = value; + } + + +/* ============================================================================= + * grid_addPath + * ============================================================================= + +void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr); +*/ + public void addPath(Vector_t pointVectorPtr) + { + int i; + int n = pointVectorPtr.getSize(); + + for(i = 1; i < (n-1); i++) { + Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i); + int x = coordinatePtr.x; + int y = coordinatePtr.y; + int z = coordinatePtr.z; + setPoint(x,y,z,GRID_POINT_FULL); + } + } + + +/* ============================================================================= + * TMgrid_addPath + * ============================================================================= + TM_CALLABLE +void +TMgrid_addPath (TM_ARGDECL grid_t* gridPtr, vector_t* pointVectorPtr); +*/ + + +/* ============================================================================= + * grid_print + * ============================================================================= +void grid_print (grid_t* gridPtr); +*/ + public void print() + { + int z; + + for(z=0;j= 0) { + return prevPtr; + } + prevPtr = nodePtr; + } + + return prevPtr; + } + + /* ============================================================================= + * list_find + * -- Returns NULL if not found, else returns pointer to data + * ============================================================================= + * void* list_find (list_t* listPtr, void* dataPtr); + */ + public Object find(Object dataPtr) { + List_Node nodePtr; + List_Node prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr == null) || + (compare(nodePtr.dataPtr,dataPtr) != 0)) { + return null; + } + + return (nodePtr.dataPtr); + } + + public int compare(Object obj1,Object obj2) + { + if(isCoordinate) + { + return Coordinate.comparePair(obj1,obj2); + } + else + return compareObject(obj1,obj2); + } + +/* ============================================================================= + * list_insert + * -- Return TRUE on success, else FALSE + * ============================================================================= + * bool_t list_insert (list_t* listPtr, void* dataPtr); + */ + public boolean insert(Object dataPtr) { + List_Node prevPtr; + List_Node nodePtr; + List_Node currPtr; + + prevPtr = findPrevious(dataPtr); + currPtr = prePtr.nextPtr; + + nodePtr = allocNode(dataPtr); + if (nodePtr == null) { + return false; + } + + nodePtr.nextPtr = currPtr; + prevPtr.nextPr = nodePtr; + size++; + + return true; + } + + +/* ============================================================================= + * list_remove + * -- Returns TRUE if successful, else FALSE + * ============================================================================= + * bool_t list_remove (list_t* listPtr, void* dataPtr); + */ + public boolean remove(Object dataPtr) + { + List_Node prevPtr; + List_Node nodePtr; + + prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr != null) && + (compare(nodePtr.dataPtr,dataPtr) == 0)) + { + prevPtr.nextPtr = nodePtr.nextPtr; + nodePtr.nextPtr = null; + nodePtr = null; + size--; + + return true; + } + + return false; + } + + int compareObject(Object obj1,Object obj2) { + return obj1 - obj2; + } + + +/* ============================================================================= + * list_clear + * -- Removes all elements + * ============================================================================= + * void list_clear (list_t* listPtr); + */ + public void clear() { + head = new List_Node(); + size = 0; + } + +/* ============================================================================= + * + * End of list.java + * + * ============================================================================= + */ + + /* Test list */ + + public static void main(String[] argv) { + List_t listPtr; + int[] data1 = new int[5]; + int[] data2 = new int [6]; + + int i; + + System.out.println("Starting..."); + } + +} + + + diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/Maze.java b/Robust/src/Benchmarks/SingleTM/Labyrinth/Maze.java new file mode 100644 index 00000000..56417db8 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/Maze.java @@ -0,0 +1,369 @@ +/*============================================================================= + * + * Maze.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * 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. + * + * ============================================================================= + */ + + +public class Maze { + Grid gridPtr; + Queue workQueuePtr; + Vector_t wallvectorPtr; /* contains source/destination pairs to route */ + Vector_t srcVectorPtr; /* obstacles */ + Vector_t dstVectorPtr; /* destinations */ + + +/* ============================================================================= + * maze_alloc + * ============================================================================= + maze_t* maze_alloc (); + */ + public static Maze alloc() + { + Maze mazePtr = new Maze(); + + if(mazePtr != null) { + mazePtr.gridPtr = null; + mazePtr.workQueuePtr = Queue.alloc(1024); + mazePtr.wallVectorPtr = Vector.alloc(1); + mazePtr.srcVectorPtr = Vector.alloc(1); + mazePtr.dstVectorPtr = Vector.alloc(1); + + } + + return mazePtr; + } + +/* ============================================================================= + * maze_free + * ============================================================================= + void maze_free (maze_t* mazePtr); + */ + public static void free(Maze m) + { + m = null; + } + +/* ============================================================================= + * addToGrid + * ============================================================================= + */ + private void addToGrid(Grid gridPtr,Vector_t vectorPtr,char[] type) + { + int i; + int n = vectorPtr.getSize(); + + for(i = 0; i < n; i++) { + Coordinate coordinatePtr = (Coordinate)vectorPtr.vector_at(i); + if(!gridPtr.isPointValid(coodinatePtr.x,coordinatePtr.y,coordinatePtr.z)) + { + System.err.println("Error: " + type + " (" + coordinate.x + + ", " + coordinate.y + + ", " + coordinate.z); + System.exit(1); + } + } + gridPtr.addPath(vectorPtr); + } +/* ============================================================================= + * maze_read + * -- Return number of path to route + * ============================================================================= + long maze_read (maze_t* mazePtr, char* inputFileName); + */ + public int read(String inputFileName) + { + BufferedReader in = new BufferedReader(new FileReader(inputFileName)); + + /* + * Parse input file + */ + int lineNumber = 0; + int height = -1; + int width = -1; + int depth = -1; + char[] line = new char[256]; + boolean isParseError = false; + List_t workListPtr = List.alloc(1); // List.alloc(Coordinate.comparePair); + String line; + + while(line = in.readLine()) { + + char code; + int[] xy = new int[6]; // equivalent to x1,y1,z1,x2,y2,z2 + int numToken = 0; + + StringTokenizer tok = new StringTokenizer(line); + + if(numToken = tok.countTokens() < 1 ) { + continue; + } + + code = (char)tok.nextElement(); + + for(i=0;i 0 && less(a[j], a[j - 1]); j--) + swap(j, j - 1, a); + return; + } + + int pm = n / 2; // small arrays, middle element + if (n > 7) + { + int pl = start; + int pn = start + n - 1; + + if (n > 40) + { // big arrays, pseudomedian of 9 + int s = n / 8; + pl = med3(pl, pl + s, pl + 2 * s, a); + pm = med3(pm - s, pm, pm + s, a); + pn = med3(pn - 2 * s, pn - s, pn, a); + } + pm = med3(pl, pm, pn, a); // mid-size, med of 3 + } + + int pa, pb, pc, pd, pv; + int r; + + pv = start; + swap(pv, pm, a); + pa = pb = start; + pc = pd = start + n - 1; + + while(true) + { + while (pb <= pc && (r = diff(a[pb],a[pv])) <= 0) + { + if (r == 0) + { + swap(pa, pb, a); + pa++; + } + pb++; + } + while (pc >= pb && (r = diff(a[pc],a[pv])) >= 0) + { + if (r == 0) + { + swap(pc, pd, a); + pd--; + } + pc--; + } + if (pb > pc) + break; + swap(pb, pc, a); + pb++; + pc--; + } + int pn = start + n; + int s; + s = Math.imin(pa - start, pb - pa); + vecswap(start, pb - s, s, a); + s = Math.imin(pd - pc, pn - pd - 1); + vecswap(pb, pn - s, s, a); + if ((s = pb - pa) > 1) + qsort(a, start, s); + if ((s = pd - pc) > 1) + qsort(a, pn - s, s); + } + + private void vecswap(int i, int j, int n, Object[] a) + { + for (; n > 0; i++, j++, n--) + swap(i, j, a); + } + + public boolean less(Object x, Object y) { + Query aQueryPtr = (Query) x; + Query bQueryPtr = (Query) y; + if(aQueryPtr.index < bQueryPtr.index) + return true; + return false; + } + + public int diff(Object x, Object y) { + Query aQueryPtr = (Query) x; + Query bQueryPtr = (Query) y; + return (aQueryPtr.index - bQueryPtr.index); + } + + /** + * main to test quick sort + **/ + /* + public static void main(String[] args) { + QuickSort qs = new QuickSort(); + Query[] queries = new Query[10]; + + Random r = new Random(); + r.random_alloc(); + r.random_seed(0); + + for(int i = 0; i<10; i++) { + queries[i] = new Query(); + queries[i].index = (int) (r.random_generate() % 100); + queries[i].value = -1; + } + + System.out.println("Before sorting"); + for(int i = 0; i<10; i++) + System.out.println("queries["+i+"]= "+ queries[i]); + + qs.sort(queries); + + System.out.println("After sorting"); + for(int i = 0; i<10; i++) + System.out.println("queries["+i+"]= "+ queries[i]); + } + */ +} diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/README b/Robust/src/Benchmarks/SingleTM/Labyrinth/README new file mode 100644 index 00000000..3bcaf631 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/README @@ -0,0 +1,71 @@ +Introduction +------------ + +Given a maze, this benchmark finds the shortest-distance paths between pairs of +starting and ending points. The routing algorithm used is Lee's algorithm [2]. + +In this algorithm, the maze is represented as a grid, where each grid point can +contain connections to adjacent, non-diagonal grid points. The algorithm +searches for a shortest path between the start and end points of a connection by +performing a breadth-first search and labeling each grid point with its distance +from the start. This expansion phase will eventually reach the end point if a +connection is possible. A second traceback phase then forms the connection by +following any path with a decreasing distance. This algorithm is guaranteed to +find the shortest path between a start and end point; however, when multiple +paths are made, one path may block another. + +When creating the transactional version of this program, the techniques +described in [3] were used. When using this benchmark, please cite [1]. + + +Compiling and Running +--------------------- + +To build the application, simply run: + + make -f + +in the source directory. For example, for the sequential flavor, run: + + make -f Makefile.seq + +By default, this produces an executable named "labyrinth", which can then be +run in the following manner: + + ./labyrinth -i + +The following input file is recommended for simulated runs: + + ./labyrinth -i inputs/random-x32-y32-z3-n96.txt + +For non-simulator runs, a larger input can be used: + + ./labyrinth -i inputs/random-x512-y512-z7-n512.txt + + +Input Files +----------- + +More input sets can be generated by using "inputs/generate.py". For example, + + inputs/generate.py 128 128 3 64 + +Will create a 128x128x3 maze grid and select 64 uniformly random start/end +point pairs. + + +References +---------- + +[1] C. Cao Minh, J. Chung, C. Kozyrakis, and K. Olukotun. STAMP: Stanford + Transactional Applications for Multi-processing. In IISWC '08: Proceedings + of The IEEE International Symposium on Workload Characterization, + September 2008. + +[2] C. Lee. An algorithm for path connections and its applications. IRE Trans. + On Electronic Computers, 1961. + +[3] I. Watson, C. Kirkham, and M. Lujan. A Study of a Transactional Parallel + Routing Algorithm. Proceedings of the 16th International Conference on + Parallel Architectures and Compilation Techniques, 2007. + diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/Router.java b/Robust/src/Benchmarks/SingleTM/Labyrinth/Router.java new file mode 100644 index 00000000..22da7ce4 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/Router.java @@ -0,0 +1,398 @@ +/* ============================================================================= + * + * Router.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * Ported to Java + * Author: Jihoon Lee + * University of California, Irvine + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * 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 MOMENTUM_ZERO 0 +#define MOMENTUM_POSX 1 +#define MOMENTUM_POSY 2 +#define MOMENTUM_POSZ 3 +#define MOMENTUM_NEGX 4 +#define MOMENTUM_NEGY 5 +#define MOMENTUM_NEGZ 6 + + +public class Router { + int xCost; + int yCost; + int zCost; + int bendCost; + + +/* ============================================================================= + * router_alloc + * ============================================================================= + * router_t* router_alloc (long xCost, long yCost, long zCost, long bendCost); + */ + public static Router alloc(int xCost,int yCost,int zCost,int bendCost) + { + Router routerPtr = new Router(); + + + Point MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX); + Point MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY); + Point MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ); + Point MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX); + Point MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY); + Point MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ); + + if(routerPtr != null) { + routerPtr.xCost = xCost; + routerPtr.yCost = yCost; + routerPtr.zCost = zCost; + routerPtr.bendCost = bendCost; + } + + return routerPtr; + } + + + + +/* ============================================================================= + * router_free + * ============================================================================= + * void router_free (router_t* routerPtr); + */ + public static void free(Router routerPtr) + { + routerPtr = null; + } + +/* ============================================================================ + * PexpandToneighbor + * ============================================================================ + */ + private void PexpandToNeighbor(Grid myGridPtr, + int x,int y,int z, int value,Queue queuePtr) + { + if (myGridPtr.isPointValid(x,y,z)) { + int neighborGridPointIndex = myGridPtr.getPointIndex(x,y,z); + int neighborValue = myGridPtr.getPoint(neighborGridPointIndex); + if (neighborValue == GRID_POINT_EMPTY) { + myGridPtr.setPoint(neighborGridPointIndex,value); + queuePtr.queue_push(neighborGridPointIndex); + } else if (neighborValue != GRID_POINT_FULL) { + + if (value < neighborValue) { + myGridPtr.setPoint(neighborGridPointIndex,value); + queuePtr.queue_push(neighborGridPointIndex); + } + } + } + } + + +/* ============================================================================ + * PdoExpansion + * ============================================================================ + */ + private boolean PdoExpansion (Router routerPtr,Grid myGridPtr,Queue queuePtr, + Coordinate srcPtr,Coordinate dstPtr) + { + int xCost = routerPtr.xCost; + 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(srcGridPointIndex); + 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()) { + int gridPointIndex = queuePtr.queue_pop(); + if(gridPointIndex == dstGridPointIndex) { + isPathFound = true; + break; + } + + int[] x = new int[1]; + int[] y = new int[1]; + int[] z = new int[1]; + + myGridPtr.getPointIndices(gridPointIndex,x,y,z); + int value = myGridPtr.getPoint(gridPointIndex); + + /* + * Check 6 neighbors + * + * Potential Optimization: Only need to check 5 of these + */ + 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); + + } /* iterate over work queue */ + + return isPathfound; + } + + +/* ============================================================================ + * traceToNeighbor + * ============================================================================ + */ + private void traceToNeighbor(Grid myGridPtr, + Point currPtr, + Point movePtr, + boolean useMomentum, + int bendCost, + Point nextPtr) + { + int x = currPtr.x + movePtr.x; + int y = currPtr.y + movePtr.y; + int z = currPtr.z + movePtr.z; + + if (myGridPtr.isPointValid(x,y,z) && + !myGridPtr.isPointEmpty(x,y,z) && + !myGridPtr.isPointFull(x,y,z)) + { + int value = myGridPtr.getPoint(x,y,z); + int b = 0; + + if (useMomentum && (currPtr.momentum != movePtr.momentum)) { + b = bendCost; + } + if ((value + b) <= nextPtr.value) { /* '=' favors neighbors over current */ + nextPtr.x = x; + nextPtr.y = y; + nextPtr.z = z; + nextPtr.value = value; + nextPtr.momentum = movePtr.momentum; + } + } + } +/* ============================================================================= + * PdoTraceback + * ============================================================================= + */ + + private Vector_t PdoTraceback(Grid gridPtr,Grid myGridPtr, + Coordinate dstPtr, int bendCost) + { + Vector_t pointVectorPtr = Vector.vector_alloc(1); + + Point next = new Point(); + next.x = dstPtr.x; + next.y = dstPtr.y; + next.z = dstPtr.z; + next.value = myGridPtr.getPoint(next.x,next.y,next.z); + next.momentum = MOMENTUM_ZERO; + + while(true) { + int gridPointIndex = gridPtr.getPointIndex(next.x,next.y,next.z); + pointVectorPtr.vector_pushBack(gridPointIndex); + myGridPtr.setPoint(next.x,next.y,next.z,GRID_POINT_FULL); + + /* Check if we are done */ + if (next.value == 0) { + break; + } + Point curr = next; + + /* + * 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_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. + */ + + if ((curr.x == next.y) && + (curr.y == next.y) && + (curr.z == next.z)) + { + next.value = curr.value; + traceToNeighbor(myGridPtr,curr,MOVE_POSX,false, bendCost, next); + traceToNeighbor(myGridPtr,curr,MOVE_POSY,false, bendCost, next); + traceToNeighbor(myGridPtr,curr,MOVE_POSZ,false, bendCost, next); + traceToNeighbor(myGridPtr,curr,MOVE_NEGX,false, bendCost, next); + traceToNeighbor(myGridPtr,curr,MOVE_NEGY,false, bendCost, next); + traceToNeighbor(myGridPtr,curr,MOVE_NEGZ,false, bendCost, next); + + if ((curr.x == next.x) && + (curr.y == next.y) && + (curr.z == next.z)) + { + pointVectorPtr.vector_free(); + return null; + } + } + } + + return pointVectorPtr; + } + +/* ============================================================================= + * router_solve + * ============================================================================= + * void router_solve (void* argPtr); + */ + public static void solve(Object argPtr) + { + // TM_THREAD_ENTER(); + Solve_Arg routerArgPtr = (SolveArg) argPtr; + Router routerPtr = routerArgPtr.routerPtr; + Maze mazePtr = routerArgPtr.mazePtr; + Vector_t myPathVectorPtr = Vector.alloc(1); + + Queue workQueuePtr = mazePtr.workqueuePtr; + Grid gridPtr = mazePtr.gridPtr; + Grid myGridPtr = Grid.alloc(gridPtr.width,gridPtr.height,gridPtr.depth); + int bendCost = routerPtr.bendCost; + Queue myExpansionQueuePtr = Queue.queue_alloc(-1); + + /* + * Iterate over work list to route each path. This involves an + * 'expansion' and 'tracback' phase for each source/destination pair. + */ + while(true) { + Pair coordinatePairPtr; + + // TM_BEGIN(); + atomic { + if(workQueuePtr.queue_isEmpty()) { + coordinatePairPtr = null; + } else { + coordinatePairPtr = (Pair)workQueuePtr.queue_pop(); + } + } + // TM_END(); + // + + if (coordinatePairPtr = null) { + break; + } + + Coordinate srcPtr = coordinatePairPtr.firstPtr; + Coordinate dstPtr = coordinatePairPtr.secondPtr; + + boolean success = false; + Vector_t pointvectorPtr = null; + + // TM_BEGIN(); + atomic { + Grid.copy(myGridPtr, gridPtr); /* ok if not most up-to-date */ + if (PdoExpansion(routerPtr, myGridPtr, myExpansionQueuePtr, + srcPtr, dstPtr)) { + pointVectorPtr = PdoTraceback(gridPtr,myGridPtr,dstPtr,bendCost); + + if (pointVectorPtr) { + gridPtr.addPath(pointVectorPtr); + success = true; + } + } + } + + if(success) { + boolean status = myPathVectorPtr.vector_pushBack(pointVectorPtr); + } + } + + /* + * Add my paths to global list + */ + List_t pathVectorListPtr = routerArgPtr.pathVectorListPtr; + + atomic { + pathVectorListPtr.insert(myPathVectorPtr); + } + + // TM_THREAD_EXIT(); + } +} +/* ============================================================================= + * + * End of router.java + * + * ============================================================================= + */ diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/Solve_arg.java b/Robust/src/Benchmarks/SingleTM/Labyrinth/Solve_arg.java new file mode 100644 index 00000000..27df282c --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/Solve_arg.java @@ -0,0 +1,15 @@ + + + public class Solve_Arg { + Router routerPtr; + Maze mazePtr; + List_t pathVectorListPtr; + + public Solve_Arg(Router r,Maze m,List_t l) + { + routerPtr = r; + mazePtr = m; + pathVectorListPtr = l; + } + } + diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/Vector_t.java b/Robust/src/Benchmarks/SingleTM/Labyrinth/Vector_t.java new file mode 100644 index 00000000..f1ae2ba1 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/Vector_t.java @@ -0,0 +1,156 @@ +public class Vector_t { + int size; + int capacity; + Object[] elements; + QuickSort qsort; + + public Vector_t() { + qsort = new QuickSort(); + } + + /* ============================================================================= + * Vector_alloc + * -- Returns null if failed + * ============================================================================= + */ + public static Vector_t vector_alloc (int initCapacity) { + int capacity = Math.imax(initCapacity, 1); + Vector_t vectorPtr = new Vector_t(); + if(vectorPtr != null) { + vectorPtr.size = 0; + vectorPtr.capacity = capacity; + vectorPtr.elements = new Object[capacity]; + if(vectorPtr.elements == null) + return null; + } + return vectorPtr; + } + + /* ============================================================================= + * Vector_free + * ============================================================================= + */ + public void + vector_free () + { + elements = null; + } + + /* ============================================================================= + * Vector_at + * -- Returns null if failed + * ============================================================================= + */ + public Object vector_at (int i) { + if ((i < 0) || (i >= size)) { + System.out.println("Illegal Vector.element\n"); + return null; + } + return (elements[i]); + } + + + /* ============================================================================= + * Vector_pushBack + * -- Returns false if fail, else true + * ============================================================================= + */ + public boolean vector_pushBack (Object dataPtr) { + if (size == capacity) { + int newCapacity = capacity * 2; + Object[] newElements = new Object[newCapacity]; + + //void** newElements = (void**)malloc(newCapacity * sizeof(void*)); + if (newElements == null) { + return false; + } + capacity = newCapacity; + for (int i = 0; i < size; i++) { + newElements[i] = elements[i]; + } + elements = null; + elements = newElements; + } + + elements[size++] = dataPtr; + + return true; + } + + /* ============================================================================= + * Vector_popBack + * -- Returns null if fail, else returns last element + * ============================================================================= + */ + public Object + vector_popBack () + { + if (size < 1) { + return null; + } + + return (elements[--(size)]); + } + + /* ============================================================================= + * Vector_getSize + * ============================================================================= + */ + public int + vector_getSize () + { + return (size); + } + + /* ============================================================================= + * Vector_clear + * ============================================================================= + */ + public void + vector_clear () + { + size = 0; + } + + /* ============================================================================= + * Vector_sort + * ============================================================================= + * + public void + vector_sort () + { + //qsort.sort(elements, 0, (elements.length - 1)); + qsort.sort(elements); + //qsort(elements, size, 4, compare); + } + + * ============================================================================= + * Vector_copy + * ============================================================================= + */ + public static boolean + vector_copy (Vector_t dstVectorPtr, Vector_t srcVectorPtr) + { + int dstCapacity = dstVectorPtr.capacity; + int srcSize = srcVectorPtr.size; + if (dstCapacity < srcSize) { + int srcCapacity = srcVectorPtr.capacity; + Object[] elements = new Object[srcCapacity]; + + if (elements == null) { + return false; + } + dstVectorPtr.elements = null; + dstVectorPtr.elements = elements; + dstVectorPtr.capacity = srcCapacity; + } + + for(int i = 0; i< srcSize; i++) { + dstVectorPtr.elements[i] = srcVectorPtr.elements[i]; + } + + dstVectorPtr.size = srcSize; + + return true; + } +} diff --git "a/Robust/src/Benchmarks/SingleTM/Labyrinth/\\" "b/Robust/src/Benchmarks/SingleTM/Labyrinth/\\" new file mode 100644 index 00000000..9402fc2a --- /dev/null +++ "b/Robust/src/Benchmarks/SingleTM/Labyrinth/\\" @@ -0,0 +1,212 @@ +/* ============================================================================= + * + * Router.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * 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. + * + * ============================================================================= + */ + + +typedef struct router_solve_arg { + router_t* routerPtr; + maze_t* mazePtr; + list_t* pathVectorListPtr; +} router_solve_arg_t; + +public class Router { + int xCost; + int yCost; + int zCost; + int bendCost; + + public class Solve_Arg { + Router routerPtr; + Maze mazePtr; + List_t pathVectorListPtr; + } + + enum { + MOMENTUM_ZERO = 0, + MOMENTUM_POSX = 1, + MOMENTUM_POSY = 2, + MOMENTUM_POSZ = 3, + MOMENTUM_NEGX = 4, + MOMENTUM_NEGY = 5, + MOMENTUM_NEGZ = 6 + } Momentum_t; + + private class Point { + int x; + int y; + int z; + int value; + Momentum_t momentum; + + public Point(int x,int y, int z,int value, Momentum_t m) { + this.x = x; + this.y = y; + this.z = z; + this.value = value; + momentum = m; + } + } + + Point MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX); + Point MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY); + Point MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ); + Point MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX); + Point MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY); + Point MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ); + + +/* ============================================================================= + * router_alloc + * ============================================================================= + * router_t* router_alloc (long xCost, long yCost, long zCost, long bendCost); + */ + public static Router alloc(int xCost,int yCost,int zCost,int bendCost) + { + Router routerPtr = new Router(); + + if(routerPtr != null) { + routerPtr.xCost = xCost; + routerPtr.yCost = yCost; + routerPtr.zCost = zCost; + routerPtr.bendCost = bendCost; + } + + return routerPtr; + } + + + + +/* ============================================================================= + * router_free + * ============================================================================= + * void router_free (router_t* routerPtr); + */ + public static void free(Router routerPtr) + { + routerPtr = null; + } + + + +/* ============================================================================ + * traceToNeighbor + * ============================================================================ + */ + private void traceToNeighbor(Grid myGridPtr, + Point currPtr, + Point movePtr, + boolean useMomentum, + int bendCost, + Point nextPtr) + { + int x = currPtr.x + movePtr.x; + int y = currPtr.y + movePtr.y; + int z = currPtr.z + movePtr.z; + + if (myGridPtr.isPointValid(x,y,z) && + !myGridPtr.isPointEmpty(x,y,z) && + !myGridPtr.isPointFull(x,y,z)) + { + int value = myGridPtr.getPoint(x,y,z); + int b = 0; + + if (useMomentum && (currPtr.momentum != movePtr.momentum)) { + b = bendCost; + } + if ((value + b) <= nextPtr.value) { /* '=' favors neighbors over current */ + nextPtr.x = x; + nextPtr.y = y; + nextPtr.z = z; + nextPtr.value = value; + nextPtr.momentum = movePtr.momentum; + } + } + } + + +/* ============================================================================= + * router_solve + * ============================================================================= + * void router_solve (void* argPtr); + */ + public void solve(Object argPtr) + { + Barrior + } + + +} + +/* ============================================================================= + * + * End of router.h + * + * ============================================================================= + */ diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/extractLines b/Robust/src/Benchmarks/SingleTM/Labyrinth/extractLines new file mode 100755 index 00000000..c75e5726 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/extractLines @@ -0,0 +1,3 @@ +#!/bin/sh +lines=$(grep -n "#" $1 | cut -d: -f1 | sed '1q') +sed '/^#/d' $1 > ttt$1 diff --git a/Robust/src/Benchmarks/SingleTM/Labyrinth/makefile b/Robust/src/Benchmarks/SingleTM/Labyrinth/makefile new file mode 100644 index 00000000..2c89deff --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Labyrinth/makefile @@ -0,0 +1,31 @@ +MAINCLASS=Labyrinth +SRC=ttttmp${MAINCLASS}.java \ + ../common/Pair.java \ + ../common/Queue_t.java \ + Vector_t.java \ + ../common/List_t.java \ + ../common/List_Node.java \ + ../common/List_Iter.java \ + Coordinate.java \ + ttttmpGrid.java \ + Maze.java \ + ttttmpRouter.java \ + Point.java \ + Solve_arg.java \ + ../../../ClassLibrary/JavaSTM/Barrier.java + +FLAGS=-mainclass ${MAINCLASS} -thread -nooptimize -debug + +default: + cpp ${MAINCLASS}.java > tmp${MAINCLASS}.java + cpp Grid.java > tmpGrid.java + cpp Router.java > tmpRouter.java + ./extractLines tmp${MAINCLASS}.java + ./extractLines tmpGrid.java + ./extractLines tmpRouter.java + ../../../buildscript ${FLAGS} -o ${MAINCLASS} ${SRC} + rm ttt*.java tmp*.java + +clean: + rm -rf tmpbuilddirectory + rm *.bin