From a9def6c0199c018c3bbfd0318b49bfcd92a72b77 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 2 May 2008 20:16:51 +0000 Subject: [PATCH] Add multiple thread version --- .../Prefetch/Em3d/dsm/BiGraphN.java | 107 ++++++++ .../Benchmarks/Prefetch/Em3d/dsm/Em3dN.java | 244 ++++++++++++++++++ .../src/Benchmarks/Prefetch/Em3d/dsm/makefile | 21 +- 3 files changed, 356 insertions(+), 16 deletions(-) create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/dsm/BiGraphN.java create mode 100644 Robust/src/Benchmarks/Prefetch/Em3d/dsm/Em3dN.java diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/dsm/BiGraphN.java b/Robust/src/Benchmarks/Prefetch/Em3d/dsm/BiGraphN.java new file mode 100644 index 00000000..9c5a8f69 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/dsm/BiGraphN.java @@ -0,0 +1,107 @@ +/** + * A class that represents the irregular bipartite graph used in + * EM3D. The graph contains two linked structures that represent the + * E nodes and the N nodes in the application. + **/ +public class BiGraph +{ + public BiGraph() { + } + /** + * Nodes that represent the electrical field. + **/ + Node[] eNodes; + /** + * Nodes that representhe the magnetic field. + **/ + Node[] hNodes; + + /** + * Construct the bipartite graph. + * @param e the nodes representing the electric fields + * @param h the nodes representing the magnetic fields + **/ + BiGraph(Node[] e, Node[] h) + { + eNodes = e; + hNodes = h; + } + + /** + * Create the bi graph that contains the linked list of + * e and h nodes. + * @param numNodes the number of nodes to create + * @param numDegree the out-degree of each node + * @param verbose should we print out runtime messages + * @return the bi graph that we've created. + **/ + + static BiGraph create(int numNodes, int numDegree, boolean verbose, Random r) + { + + // making nodes (we create a table) + //if (verbose) System.printString("making nodes (tables in orig. version)"); + Node [] eTable=Node.fillTable(numNodes, numDegree, r); + Node [] hTable=Node.fillTable(numNodes, numDegree, r); + + // making neighbors + //if (verbose) System.printString("updating from and coeffs"); + for(int i = 0; i< numNodes; i++) { + Node n = hTable[i]; + n.makeUniqueNeighbors(eTable, r); + } + + for (int i = 0; i < numNodes; i++) { + Node n = eTable[i]; + n.makeUniqueNeighbors(hTable, r); + } + + // Create the fromNodes and coeff field + //if (verbose) System.printString("filling from fields"); + for(int i = 0; i< numNodes; i++) { + Node n = hTable[i]; + n.makeFromNodes(); + } + + for (int i = 0; i < numNodes; i++) { + Node n = eTable[i]; + n.makeFromNodes(); + } + + // Update the fromNodes + for (int i = 0; i < numNodes; i++) { + Node n = hTable[i]; + n.updateFromNodes(r); + } + for (int i = 0; i < numNodes; i++) { + Node n = eTable[i]; + n.updateFromNodes(r); + } + + BiGraph g = global new BiGraph(eTable, hTable); + return g; + } + + /** + * Override the toString method to print out the values of the e and h nodes. + * @return a string contain the values of the e and h nodes. + **/ + public String toString() + { + StringBuffer retval = new StringBuffer(); + Node tmp = eNodes[0]; + while(tmp!=null) { + Node n = tmp; + retval.append("E: " + n + "\n"); + tmp = tmp.next; + } + tmp = hNodes[0]; + while(tmp!=null) { + Node n = tmp; + retval.append("H: " + n + "\n"); + tmp = tmp.next; + } + return retval.toString(); + } + +} diff --git a/Robust/src/Benchmarks/Prefetch/Em3d/dsm/Em3dN.java b/Robust/src/Benchmarks/Prefetch/Em3d/dsm/Em3dN.java new file mode 100644 index 00000000..e9355cce --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Em3d/dsm/Em3dN.java @@ -0,0 +1,244 @@ +/** + * + * + * 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 extends Thread +{ + + /** + * 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 numThreads; + + BiGraph bg; + int upperlimit; + int lowerlimit; + Barrier mybarr; + + public Em3d() { + numNodes = 0; + numDegree = 0; + numIter = 1; + printResult = false; + printMsgs = false; + } + + public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr) { + this.bg = bg; + this.lowerlimit = lowerlimit; + this.upperlimit = upperlimit; + this.numIter = numIter; + this.mybarr = mybarr; + } + + public void run() { + int iteration; + Barrier barr; + + atomic { + iteration = numIter; + barr=mybarr; + } + + for (int i = 0; i < iteration; i++) { + /* for eNodes */ + atomic { + for(int j = lowerlimit; j numThreads = " + numThreads+"\n"); + Barrier mybarr; + BiGraph graph; + Random rand = new Random(783); + + atomic { + mybarr = global new Barrier(numThreads); + graph = BiGraph.create(em.numNodes, em.numDegree, em.printResult, rand); + } + + long end0 = System.currentTimeMillis(); + + // compute a single iteration of electro-magnetic propagation + if (em.printMsgs) + System.printString("Propagating field values for " + em.numIter + + " iteration(s)...\n"); + long start1 = System.currentTimeMillis(); + Em3d[] em3d; + + atomic { + em3d = global new Em3d[numThreads]; + int increment=em.numNodes/numThreads; + 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/dsm/makefile b/Robust/src/Benchmarks/Prefetch/Em3d/dsm/makefile index db09624d..f7031ad3 100644 --- a/Robust/src/Benchmarks/Prefetch/Em3d/dsm/makefile +++ b/Robust/src/Benchmarks/Prefetch/Em3d/dsm/makefile @@ -3,30 +3,19 @@ SRC=${MAINCLASS}.java \ BiGraph.java \ Node.java \ Barrier.java -SRC1=${MAINCLASS}1.java \ - BiGraph.java \ - Node.java \ - Barrier.java -SRC2=${MAINCLASS}2.java \ - BiGraph.java \ - Node.java \ - Barrier.java -SRC4=${MAINCLASS}4.java \ - BiGraph.java \ +SRC1=${MAINCLASS}N.java \ + BiGraphN.java \ Node.java \ Barrier.java + FLAGS=-dsm -prefetch -excprefetch Em3d.main -excprefetch BiGraph.create -excprefetch Node.Node -excprefetch Node.fillTable -excprefetch Node.makeUniqueNeighbors -excprefetch Node.makeFromNodes -excprefetch Node.updateFromNodes -nooptimize -profile -debug -mainclass ${MAINCLASS} FLAGS2=-dsm -nooptimize -profile -debug -mainclass ${MAINCLASS} default: # ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}NP ${SRC} # ../../../../buildscript ${FLAGS} -o ${MAINCLASS} ${SRC} - ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}1NP ${SRC1} - ../../../../buildscript ${FLAGS} -o ${MAINCLASS}1 ${SRC1} - ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}2NP ${SRC2} - ../../../../buildscript ${FLAGS} -o ${MAINCLASS}2 ${SRC2} - ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}4NP ${SRC4} - ../../../../buildscript ${FLAGS} -o ${MAINCLASS}4 ${SRC4} + ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}NNP ${SRC1} + ../../../../buildscript ${FLAGS} -o ${MAINCLASS}N ${SRC1} clean: rm -rf tmpbuilddirectory -- 2.34.1