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;
49 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr, int numDegree, int threadindex) {
51 this.lowerlimit = lowerlimit;
52 this.upperlimit = upperlimit;
53 this.numIter = numIter;
55 this.numDegree = numDegree;
56 this.threadindex=threadindex;
69 random = new Random(lowerlimit);
73 //This is going to conflict badly...Minimize work here
74 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
76 Barrier.enterBarrier(barr);
79 //initialize the eNodes
80 bg.initializeNodes(bg.eNodes, bg.hNodes, lowerlimit, upperlimit, degree, random, threadindex);
82 Barrier.enterBarrier(barr);
85 //initialize the hNodes
86 bg.initializeNodes(bg.hNodes, bg.eNodes, lowerlimit, upperlimit, degree, random, threadindex);
88 Barrier.enterBarrier(barr);
91 bg.makeFromNodes(bg.hNodes, lowerlimit, upperlimit, random);
93 Barrier.enterBarrier(barr);
96 bg.makeFromNodes(bg.eNodes, 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-1
143 mid[1] = (128<<24)|(195<<16)|(175<<8)|80;//dw-2
144 mid[2] = (128<<24)|(195<<16)|(175<<8)|73;
145 mid[3] = (128<<24)|(195<<16)|(175<<8)|78;
146 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
151 // initialization step 1: allocate BiGraph
152 // System.printString( "Allocating BiGraph.\n" );
155 mybarr = global new Barrier(numThreads);
156 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
159 Em3dWrap[] em3d=new Em3dWrap[numThreads];
160 int increment = em.numNodes/numThreads;
163 // initialization step 2: divide work of allocating nodes
164 // System.printString( "Launching distributed allocation of nodes.\n" );
168 for(int i=0;i<numThreads;i++) {
170 if ((i+1)==numThreads)
171 tmp = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr, em.numDegree, i);
173 tmp = global new Em3d(graph, base, base+increment, em.numIter, mybarr, em.numDegree, i);
174 em3d[i]=new Em3dWrap(tmp);
179 for(int i = 0; i<numThreads; i++) {
180 em3d[i].em3d.start(mid[i]);
183 for(int i = 0; i<numThreads; i++) {
190 * Parse the command line options.
191 * @param args the command line options.
194 public static void parseCmdLine(String args[], Em3d em)
199 while (i < args.length && args[i].startsWith("-")) {
202 // check for options that require arguments
203 if (arg.equals("-N")) {
204 if (i < args.length) {
205 em.numNodes = new Integer(args[i++]).intValue();
207 } else if (arg.equals("-T")) {
208 if (i < args.length) {
209 em.numThreads = new Integer(args[i++]).intValue();
211 } else if (arg.equals("-d")) {
212 if (i < args.length) {
213 em.numDegree = new Integer(args[i++]).intValue();
215 } else if (arg.equals("-i")) {
216 if (i < args.length) {
217 em.numIter = new Integer(args[i++]).intValue();
219 } else if (arg.equals("-p")) {
220 em.printResult = true;
221 } else if (arg.equals("-m")) {
223 } else if (arg.equals("-h")) {
228 if (em.numNodes == 0 || em.numDegree == 0)
233 * The usage routine which describes the program options.
237 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
238 System.printString(" -N the number of nodes\n");
239 System.printString(" -T the number of threads\n");
240 System.printString(" -d the out-degree of each node\n");
241 System.printString(" -i the number of iterations\n");
242 System.printString(" -p (print detailed results\n)");
243 System.printString(" -m (print informative messages)\n");
244 System.printString(" -h (this message)\n");