4 * Java implementation of the <tt>em3d</tt> Olden benchmark. This Olden
5 * benchmark models the propagation of electromagnetic waves through
6 * objects in 3 dimensions. It is a simple computation on an irregular
7 * bipartite graph containing nodes representing electric and magnetic
11 * D. Culler, A. Dusseau, S. Goldstein, A. Krishnamurthy, S. Lumetta, T. von
12 * Eicken and K. Yelick. "Parallel Programming in Split-C". Supercomputing
13 * 1993, pages 262-273.
16 public class Em3d extends Thread {
19 * The number of nodes (E and H)
23 * The out-degree of each node.
25 private int numDegree;
27 * The number of compute iterations
31 * Should we print the results and other runtime messages
33 private boolean printResult;
35 * Print information messages?
37 private boolean printMsgs;
48 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, int numDegree, int threadindex) {
50 this.lowerlimit = lowerlimit;
51 this.upperlimit = upperlimit;
52 this.numIter = numIter;
53 this.numDegree = numDegree;
54 this.threadindex=threadindex;
64 barr = new Barrier("128.195.175.79");
68 random = new Random(lowerlimit);
72 //This is going to conflict badly...Minimize work here
73 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
75 Barrier.enterBarrier(barr);
76 System.clearPrefetchCache();
79 //initialize the eNodes
80 bg.initializeNodes(bg.eNodes, bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, degree, random, threadindex);
82 Barrier.enterBarrier(barr);
85 //initialize the hNodes
86 bg.initializeNodes(bg.hNodes, bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, degree, random, threadindex);
88 Barrier.enterBarrier(barr);
91 bg.makeFromNodes(bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, random);
93 Barrier.enterBarrier(barr);
96 bg.makeFromNodes(bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, random);
98 Barrier.enterBarrier(barr);
101 for (int i = 0; i < iteration; i++) {
104 for(int j = lowerlimit; j<upperlimit; j++) {
105 Node n = bg.eNodes[j];
107 for (int k = 0; k < n.fromCount; k++) {
108 n.value -= n.coeffs[k] * n.fromNodes[k].value;
113 Barrier.enterBarrier(barr);
117 for(int j = lowerlimit; j<upperlimit; j++) {
118 Node n = bg.hNodes[j];
119 for (int k = 0; k < n.fromCount; k++) {
120 n.value -= n.coeffs[k] * n.fromNodes[k].value;
124 Barrier.enterBarrier(barr);
129 * The main roitine that creates the irregular, linked data structure
130 * that represents the electric and magnetic fields and propagates the
131 * waves through the graph.
132 * @param args the command line arguments
134 public static void main(String args[]) {
135 Em3d em = new Em3d();
136 Em3d.parseCmdLine(args, em);
138 System.printString("Initializing em3d random graph...\n");
139 long start0 = System.currentTimeMillis();
140 int numThreads = em.numThreads;
141 int[] mid = new int[4];
142 mid[0] = (128<<24)|(195<<16)|(175<<8)|79;//dw-8
143 mid[1] = (128<<24)|(195<<16)|(175<<8)|80;//dw-9
144 mid[2] = (128<<24)|(195<<16)|(175<<8)|78;//dw-7
145 mid[3] = (128<<24)|(195<<16)|(175<<8)|73;//dw-5
147 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
148 BarrierServer mybarr;
152 // initialization step 1: allocate BiGraph
153 // System.printString( "Allocating BiGraph.\n" );
156 mybarr = global new BarrierServer(numThreads);
157 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
159 mybarr.start(mid[0]);
162 Em3dWrap[] em3d=new Em3dWrap[numThreads];
163 int increment = em.numNodes/numThreads;
166 // initialization step 2: divide work of allocating nodes
167 // System.printString( "Launching distributed allocation of nodes.\n" );
171 for(int i=0;i<numThreads;i++) {
173 if ((i+1)==numThreads)
174 tmp = global new Em3d(graph, base, em.numNodes, em.numIter, em.numDegree, i);
176 tmp = global new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i);
177 em3d[i]=new Em3dWrap(tmp);
182 boolean waitfordone=true;
190 //System.printString("Starting Barrier run\n");
191 for(int i = 0; i<numThreads; i++) {
192 em3d[i].em3d.start(mid[i]);
194 for(int i = 0; i<numThreads; i++) {
197 System.printString("Done!"+ "\n");
202 * Parse the command line options.
203 * @param args the command line options.
206 public static void parseCmdLine(String args[], Em3d em)
211 while (i < args.length && args[i].startsWith("-")) {
214 // check for options that require arguments
215 if (arg.equals("-N")) {
216 if (i < args.length) {
217 em.numNodes = new Integer(args[i++]).intValue();
219 } else if (arg.equals("-T")) {
220 if (i < args.length) {
221 em.numThreads = new Integer(args[i++]).intValue();
223 } else if (arg.equals("-d")) {
224 if (i < args.length) {
225 em.numDegree = new Integer(args[i++]).intValue();
227 } else if (arg.equals("-i")) {
228 if (i < args.length) {
229 em.numIter = new Integer(args[i++]).intValue();
231 } else if (arg.equals("-p")) {
232 em.printResult = true;
233 } else if (arg.equals("-m")) {
235 } else if (arg.equals("-h")) {
240 if (em.numNodes == 0 || em.numDegree == 0)
245 * The usage routine which describes the program options.
249 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
250 System.printString(" -N the number of nodes\n");
251 System.printString(" -T the number of threads\n");
252 System.printString(" -d the out-degree of each node\n");
253 System.printString(" -i the number of iterations\n");
254 System.printString(" -p (print detailed results\n)");
255 System.printString(" -m (print informative messages)\n");
256 System.printString(" -h (this message)\n");