From 78f86fad39a1ea1361bdef1bcb68d5f14d341098 Mon Sep 17 00:00:00 2001 From: adash Date: Mon, 27 Oct 2008 19:55:34 +0000 Subject: [PATCH] Java non transactional version for Em3d --- .../Em3d/javasingle/BarrierNonDSM.java | 50 ++++ .../Prefetch/Em3d/javasingle/BiGraph2.java | 107 ++++++++ .../Prefetch/Em3d/javasingle/EVector.java | 83 ++++++ .../Prefetch/Em3d/javasingle/Em3d2.java | 249 ++++++++++++++++++ .../Prefetch/Em3d/javasingle/Em3dWrap.java | 9 + .../Prefetch/Em3d/javasingle/Node2.java | 122 +++++++++ .../Prefetch/Em3d/javasingle/makefile | 13 + 7 files changed, 633 insertions(+) create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/BarrierNonDSM.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/BiGraph2.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/EVector.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3d2.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3dWrap.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Node2.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/javasingle/makefile diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/BarrierNonDSM.java b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/BarrierNonDSM.java new file mode 100644 index 00000000..db27fbb5 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/BarrierNonDSM.java @@ -0,0 +1,50 @@ +public class BarrierServer { + int numthreads; + boolean done; + + public BarrierServer(int n) { + numthreads=n; + done=false; + } + + public void run() { + int n; + ServerSocket ss=new ServerSocket(2000); + n=numthreads; + done=true; + Socket ar[]=new Socket[n]; + for(int i=0; i=size) { + System.printString("Illegal Vector.elementAt"); + return null; + } + return array[index]; + } + + public void setElementAt(Object obj, int index) { + if (index>=0 && index array.length) { + int newsize; + if (capacityIncrement<=0) + newsize=array.length*2; + else + newsize=array.length+capacityIncrement; + if (newsize=size) + System.printString("Illegal remove"); + for(int i=index;i<(size-1);i++) { + array[i]=array[i+1]; + } + size--; + } +} diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3d2.java b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3d2.java new file mode 100644 index 00000000..0abfad2b --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3d2.java @@ -0,0 +1,249 @@ +/** + * + * + * Java implementation of the em3d Olden benchmark. This Olden + * benchmark models the propagation of electromagnetic waves through + * objects in 3 dimensions. It is a simple computation on an irregular + * bipartite graph containing nodes representing electric and magnetic + * field values. + * + *

+ * D. Culler, A. Dusseau, S. Goldstein, A. Krishnamurthy, S. Lumetta, T. von + * Eicken and K. Yelick. "Parallel Programming in Split-C". Supercomputing + * 1993, pages 262-273. + * + **/ +public class Em3d { + + /** + * The number of nodes (E and H) + **/ + private int numNodes; + /** + * The out-degree of each node. + **/ + private int numDegree; + /** + * The number of compute iterations + **/ + private int numIter; + /** + * Should we print the results and other runtime messages + **/ + private boolean printResult; + /** + * Print information messages? + **/ + private boolean printMsgs; + + int threadindex; + int numThreads; + + BiGraph bg; + int upperlimit; + int lowerlimit; + public Em3d() { + } + + public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, int numDegree, int threadindex) { + this.bg = bg; + this.lowerlimit = lowerlimit; + this.upperlimit = upperlimit; + this.numIter = numIter; + this.numDegree = numDegree; + this.threadindex=threadindex; + } + + public void run() { + int iteration; + //Barrier barr; + int degree; + Random random; + String hname; + + //barr = new Barrier("128.195.175.84"); + iteration = numIter; + degree = numDegree; + random = new Random(lowerlimit); + + //This is going to conflict badly...Minimize work here + bg.allocateNodes ( lowerlimit, upperlimit, threadindex); + //Barrier.enterBarrier(barr); + + + //initialize the eNodes + bg.initializeNodes(bg.eNodes, bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, degree, random, threadindex); + //Barrier.enterBarrier(barr); + + //initialize the hNodes + bg.initializeNodes(bg.hNodes, bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, degree, random, threadindex); + //Barrier.enterBarrier(barr); + + bg.makeFromNodes(bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, random); + //Barrier.enterBarrier(barr); + + bg.makeFromNodes(bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, random); + //Barrier.enterBarrier(barr); + + //Do the computation + for (int i = 0; i < iteration; i++) { + /* for eNodes */ + for(int j = lowerlimit; j numThreads = " + numThreads+"\n"); + //BarrierServer mybarr; + BiGraph graph; + + + // initialization step 1: allocate BiGraph + // System.printString( "Allocating BiGraph.\n" ); + + //mybarr = new BarrierServer(numThreads); + graph = BiGraph.create(em.numNodes, em.numDegree, numThreads); + //mybarr.run(); + //mybarr.start(mid[0]); + + + Em3dWrap[] em3d=new Em3dWrap[numThreads]; + int increment = em.numNodes/numThreads; + + + // initialization step 2: divide work of allocating nodes + // System.printString( "Launching distributed allocation of nodes.\n" ); + + int base=0; + for(int i=0;i -N -d [-p] [-m] [-h]\n"); + System.printString(" -N the number of nodes\n"); + System.printString(" -T the number of threads\n"); + System.printString(" -d the out-degree of each node\n"); + System.printString(" -i the number of iterations\n"); + System.printString(" -p (print detailed results\n)"); + System.printString(" -m (print informative messages)\n"); + System.printString(" -h (this message)\n"); + } + +} diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3dWrap.java b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3dWrap.java new file mode 100644 index 00000000..18fdfc60 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Em3dWrap.java @@ -0,0 +1,9 @@ +public class Em3dWrap { + public Em3d em3d; + public Em3dWrap() { + } + + public Em3dWrap(Em3d e) { + em3d=e; + } +} diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Node2.java b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Node2.java new file mode 100644 index 00000000..07152b2e --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Node2.java @@ -0,0 +1,122 @@ +/** + * This class implements nodes (both E- and H-nodes) of the EM graph. Sets + * up random neighbors and propagates field values among neighbors. + */ +public class Node { + /** + * The value of the node. + **/ + double value; + /** + * Array of nodes to which we send our value. + **/ + Node[] toNodes; + /** + * Array of nodes from which we receive values. + **/ + Node[] fromNodes; + /** + * Coefficients on the fromNodes edges + **/ + double[] coeffs; + /** + * The number of fromNodes edges + **/ + int fromCount; + /** + * Used to create the fromEdges - keeps track of the number of edges that have + * been added + **/ + int fromLength; + + /** + * Constructor for a node with given `degree'. The value of the + * node is initialized to a random value. + **/ + public Node() { + } + + public void init(int degree, double val) { + this.value=val; + // create empty array for holding toNodes + toNodes = new Node[degree]; + } + + /** + * Create unique `degree' neighbors from the nodes given in nodeTable. + * We do this by selecting a random node from the give nodeTable to + * be neighbor. If this neighbor has been previously selected, then + * a different random neighbor is chosen. + * @param nodeTable the list of nodes to choose from. + **/ + public void makeUniqueNeighbors(EVector[] reversetable,Node[] nodeTable, Random rand, int begin, int end) { + int len=toNodes.length; + for (int filled = 0; filled < len; filled++) { + int k; + Node otherNode; + int index; + do { + boolean isBreak = false; + // generate a random number in the correct range + index = rand.nextInt(); + if (index < 0) index = -index; + //local vs remote from em3d benchmark + if (filled<(len/4)) + index=index%nodeTable.length; + else + index=begin+(index%(end-begin)); + + // find a node with the random index in the given table + otherNode = nodeTable[index]; + + for (k = 0; (k < filled) && (isBreak==false); k++) { + if (otherNode == toNodes[k]) + isBreak = true; + } + } while (k < filled); + + // other node is definitely unique among "filled" toNodes + toNodes[filled] = otherNode; + + // update fromCount for the other node + if (reversetable[index]==null) + reversetable[index]=new EVector(); + reversetable[index].addElement(this); + } + } + + /** + * Allocate the right number of FromNodes for this node. This + * step can only happen once we know the right number of from nodes + * to allocate. Can be done after unique neighbors are created and known. + * + * It also initializes random coefficients on the edges. + **/ + + public void makeFromNodes() { + fromNodes = new Node[fromCount]; // nodes fill be filled in later + coeffs = new double[fromCount]; + } + + /** + * Fill in the fromNode field in "other" nodes which are pointed to + * by this node. + **/ + public void updateFromNodes(Random rand) { + for (int i = 0; i < toNodes.length; i++) { + Node otherNode = toNodes[i]; + int count = otherNode.fromLength++; + otherNode.fromNodes[count] = this; + otherNode.coeffs[count] = rand.nextDouble(); + } + } + + /** + * Override the toString method to return the value of the node. + * @return the value of the node. + **/ + public String toString() { + String returnString; + returnString = "value " + (long)value + ", from_count " + fromCount; + } +} diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/makefile b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/makefile new file mode 100644 index 00000000..9242ab44 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/javasingle/makefile @@ -0,0 +1,13 @@ +MAINCLASS=Em3d +SRC=${MAINCLASS}2.java \ + ${MAINCLASS}Wrap.java \ + BiGraph2.java \ + Node2.java \ + EVector.java \ + BarrierNonDSM.java +default: + ../../../../buildscript -optimize -mainclass ${MAINCLASS} ${SRC} -o ${MAINCLASS} + +clean: + rm -rf tmpbuilddirectory + rm *.bin -- 2.34.1