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
20 * The number of nodes (E and H)
24 * The out-degree of each node.
26 private int numDegree;
28 * The number of compute iterations
32 * Should we print the results and other runtime messages
34 private boolean printResult;
36 * Print information messages?
38 private boolean printMsgs;
49 // yipes! static members are not supported so
50 // using the following constants:
51 // runMode == 1 is RUNMODE_ALLOC
52 // runMode == 2 is RUNMODE_NEIGHBORS
53 // runMode == 3 is RUNMODE_MAKEFROM
54 // runMode == 4 is RUNMODE_FROMLINKS
55 // runMode == 5 is RUNMODE_WORK
68 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr, int numDegree, Random r, int runMode) {
70 this.lowerlimit = lowerlimit;
71 this.upperlimit = upperlimit;
72 this.numIter = numIter;
74 this.runMode = runMode;
75 this.numDegree = numDegree;
96 bg.allocate( lowerlimit, upperlimit, degree, r );
98 Barrier.enterBarrier(barr);
99 System.clearPrefetchCache();
101 } else if( mode == 2 ) {
103 bg.makeNeighbors( lowerlimit, upperlimit, r );
105 Barrier.enterBarrier(barr);
106 System.clearPrefetchCache();
108 } else if( mode == 3 ) {
110 bg.makeFromNodes( lowerlimit, upperlimit );
112 Barrier.enterBarrier(barr);
113 System.clearPrefetchCache();
115 } else if( mode == 4 ) {
117 bg.makeFromLinks( lowerlimit, upperlimit, r );
119 Barrier.enterBarrier(barr);
120 System.clearPrefetchCache();
122 } else if( mode == 5 ) {
124 for (int i = 0; i < iteration; i++) {
127 for(int j = lowerlimit; j<upperlimit; j++) {
128 Node n = bg.eNodes[j];
130 for (int k = 0; k < n.fromCount; k++) {
131 n.value -= n.coeffs[k] * n.fromNodes[k].value;
136 Barrier.enterBarrier(barr);
137 System.clearPrefetchCache();
141 for(int j = lowerlimit; j<upperlimit; j++) {
142 Node n = bg.hNodes[j];
143 for (int k = 0; k < n.fromCount; k++) {
144 n.value -= n.coeffs[k] * n.fromNodes[k].value;
148 Barrier.enterBarrier(barr);
149 System.clearPrefetchCache();
156 * The main roitine that creates the irregular, linked data structure
157 * that represents the electric and magnetic fields and propagates the
158 * waves through the graph.
159 * @param args the command line arguments
161 public static void main(String args[]) {
162 Em3d em = new Em3d();
163 Em3d.parseCmdLine(args, em);
165 System.printString("Initializing em3d random graph...\n");
166 long start0 = System.currentTimeMillis();
167 int numThreads = em.numThreads;
168 int[] mid = new int[4];
169 mid[0] = (128<<24)|(195<<16)|(175<<8)|69;//dw-1
170 mid[1] = (128<<24)|(195<<16)|(175<<8)|70;//dw-2
171 mid[2] = (128<<24)|(195<<16)|(175<<8)|73;
172 mid[3] = (128<<24)|(195<<16)|(175<<8)|78;
173 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
179 // initialization step 1: allocate BiGraph
180 System.printString( "Allocating BiGraph.\n" );
183 mybarr = global new Barrier(numThreads);
184 rand = global new Random(783);
185 graph = BiGraph.create(em.numNodes, em.numDegree, em.printResult, rand);
194 increment = em.numNodes/numThreads;
197 // initialization step 2: divide work of allocating nodes
198 System.printString( "Launching distributed allocation of nodes.\n" );
201 em3d = global new Em3d[numThreads];
203 for(int i=0;i<numThreads;i++) {
204 if ((i+1)==numThreads)
205 em3d[i] = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr, em.numDegree, rand, 1);
207 em3d[i] = global new Em3d(graph, base, base+increment, em.numIter, mybarr, em.numDegree, rand, 1);
212 for(int i = 0; i<numThreads; i++) {
219 for(int i = 0; i<numThreads; i++) {
226 // initialization step 3: link together the ends of segments
227 // that were allocated and internally linked in step 2
228 System.printString( "Linking together allocated segments.\n" );
231 for(int i = 0; i < numThreads - 1; i++) {
233 graph.linkSegments( base + increment );
238 // initialization step 4: divide work of making links
239 System.printString( "Launching distributed neighbor initialization.\n" );
242 em3d = global new Em3d[numThreads];
244 for(int i=0;i<numThreads;i++) {
245 if ((i+1)==numThreads)
246 em3d[i] = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr, em.numDegree, rand, 2);
248 em3d[i] = global new Em3d(graph, base, base+increment, em.numIter, mybarr, em.numDegree, rand, 2);
253 for(int i = 0; i<numThreads; i++) {
260 for(int i = 0; i<numThreads; i++) {
267 // initialization step 5: divide work of making from links
268 System.printString( "Launching distributed makeFromNodes initialization.\n" );
271 em3d = global new Em3d[numThreads];
273 for(int i=0;i<numThreads;i++) {
274 if ((i+1)==numThreads)
275 em3d[i] = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr, em.numDegree, rand, 3);
277 em3d[i] = global new Em3d(graph, base, base+increment, em.numIter, mybarr, em.numDegree, rand, 3);
282 for(int i = 0; i<numThreads; i++) {
289 for(int i = 0; i<numThreads; i++) {
296 // initialization step 6: divide work of making from links
297 System.printString( "Launching distributed fromLink initialization.\n" );
300 em3d = global new Em3d[numThreads];
302 for(int i=0;i<numThreads;i++) {
303 if ((i+1)==numThreads)
304 em3d[i] = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr, em.numDegree, rand, 4);
306 em3d[i] = global new Em3d(graph, base, base+increment, em.numIter, mybarr, em.numDegree, rand, 4);
311 for(int i = 0; i<numThreads; i++) {
318 for(int i = 0; i<numThreads; i++) {
325 // initialization complete
326 System.printString( "Initialization complete.\n" );
328 long end0 = System.currentTimeMillis();
331 // compute a single iteration of electro-magnetic propagation
333 System.printString("Propagating field values for " + em.numIter +
334 " iteration(s)...\n");
335 long start1 = System.currentTimeMillis();
338 em3d = global new Em3d[numThreads];
340 for(int i=0;i<numThreads;i++) {
341 if ((i+1)==numThreads)
342 em3d[i] = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr, em.numDegree, rand, 5);
344 em3d[i] = global new Em3d(graph, base, base+increment, em.numIter, mybarr, em.numDegree, rand, 5);
349 for(int i = 0; i<numThreads; i++) {
356 for(int i = 0; i<numThreads; i++) {
362 long end1 = System.currentTimeMillis();
364 // print current field values
365 if (em.printResult) {
366 StringBuffer retval = new StringBuffer();
369 dvalue = graph.hNodes[0].value;
371 int intvalue = (int)dvalue;
375 System.printString("EM3D build time "+ (long)((end0 - start0)/1000.0) + "\n");
376 System.printString("EM3D compute time " + (long)((end1 - start1)/1000.0) + "\n");
377 System.printString("EM3D total time " + (long)((end1 - start0)/1000.0) + "\n");
379 System.printString("Done!"+ "\n");
384 * Parse the command line options.
385 * @param args the command line options.
388 public static void parseCmdLine(String args[], Em3d em)
393 while (i < args.length && args[i].startsWith("-")) {
396 // check for options that require arguments
397 if (arg.equals("-N")) {
398 if (i < args.length) {
399 em.numNodes = new Integer(args[i++]).intValue();
401 } else if (arg.equals("-T")) {
402 if (i < args.length) {
403 em.numThreads = new Integer(args[i++]).intValue();
405 } else if (arg.equals("-d")) {
406 if (i < args.length) {
407 em.numDegree = new Integer(args[i++]).intValue();
409 } else if (arg.equals("-i")) {
410 if (i < args.length) {
411 em.numIter = new Integer(args[i++]).intValue();
413 } else if (arg.equals("-p")) {
414 em.printResult = true;
415 } else if (arg.equals("-m")) {
417 } else if (arg.equals("-h")) {
422 if (em.numNodes == 0 || em.numDegree == 0)
427 * The usage routine which describes the program options.
431 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
432 System.printString(" -N the number of nodes\n");
433 System.printString(" -T the number of threads\n");
434 System.printString(" -d the out-degree of each node\n");
435 System.printString(" -i the number of iterations\n");
436 System.printString(" -p (print detailed results\n)");
437 System.printString(" -m (print informative messages)\n");
438 System.printString(" -h (this message)\n");