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;
50 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, int numDegree, int threadindex, String name) {
52 this.lowerlimit = lowerlimit;
53 this.upperlimit = upperlimit;
54 this.numIter = numIter;
56 this.numDegree = numDegree;
57 this.threadindex=threadindex;
66 barr = new Barrier(hostname);
70 random = new Random(lowerlimit);
74 //This is going to conflict badly...Minimize work here
75 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
77 Barrier.enterBarrier(barr);
78 System.clearPrefetchCache();
81 //initialize the eNodes
82 bg.initializeNodes(bg.eNodes, bg.hNodes, lowerlimit, upperlimit, degree, random, threadindex);
84 Barrier.enterBarrier(barr);
87 //initialize the hNodes
88 bg.initializeNodes(bg.hNodes, bg.eNodes, lowerlimit, upperlimit, degree, random, threadindex);
90 Barrier.enterBarrier(barr);
93 bg.makeFromNodes(bg.hNodes, lowerlimit, upperlimit, random);
95 Barrier.enterBarrier(barr);
98 bg.makeFromNodes(bg.eNodes, lowerlimit, upperlimit, random);
100 Barrier.enterBarrier(barr);
103 for (int i = 0; i < iteration; i++) {
106 for(int j = lowerlimit; j<upperlimit; j++) {
107 Node n = bg.eNodes[j];
109 for (int k = 0; k < n.fromCount; k++) {
110 n.value -= n.coeffs[k] * n.fromNodes[k].value;
115 Barrier.enterBarrier(barr);
119 for(int j = lowerlimit; j<upperlimit; j++) {
120 Node n = bg.hNodes[j];
121 for (int k = 0; k < n.fromCount; k++) {
122 n.value -= n.coeffs[k] * n.fromNodes[k].value;
126 Barrier.enterBarrier(barr);
131 * The main roitine that creates the irregular, linked data structure
132 * that represents the electric and magnetic fields and propagates the
133 * waves through the graph.
134 * @param args the command line arguments
136 public static void main(String args[]) {
137 Em3d em = new Em3d();
138 Em3d.parseCmdLine(args, em);
140 System.printString("Initializing em3d random graph...\n");
141 long start0 = System.currentTimeMillis();
142 int numThreads = em.numThreads;
143 int[] mid = new int[4];
146 hostname = global new String[4];
147 hostname[0] = global new String("128.195.175.79");
148 hostname[1] = global new String("128.195.175.73");
149 hostname[2] = global new String("128.195.175.78");
150 hostname[3] = global new String("128.195.175.69");
152 mid[0] = (128<<24)|(195<<16)|(175<<8)|79;//dw-1
153 mid[1] = (128<<24)|(195<<16)|(175<<8)|73;//dw-2
154 mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
155 mid[3] = (128<<24)|(195<<16)|(175<<8)|69;
157 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
158 BarrierServer mybarr;
162 // initialization step 1: allocate BiGraph
163 // System.printString( "Allocating BiGraph.\n" );
166 mybarr = global new BarrierServer(numThreads);
167 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
170 Em3dWrap[] em3d=new Em3dWrap[numThreads];
171 int increment = em.numNodes/numThreads;
174 // initialization step 2: divide work of allocating nodes
175 // System.printString( "Launching distributed allocation of nodes.\n" );
179 for(int i=0;i<numThreads;i++) {
181 if ((i+1)==numThreads)
182 tmp = global new Em3d(graph, base, em.numNodes, em.numIter, em.numDegree, i, hostname[0]);
184 tmp = global new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i, hostname[0]);
185 em3d[i]=new Em3dWrap(tmp);
190 //TODO check if correct
191 mybarr.start(mid[0]);
192 for(int i = 0; i<numThreads; i++) {
193 em3d[i].em3d.start(mid[i]);
197 for(int i = 0; i<numThreads; i++) {
200 System.printString("Done!"+ "\n");
205 * Parse the command line options.
206 * @param args the command line options.
209 public static void parseCmdLine(String args[], Em3d em)
214 while (i < args.length && args[i].startsWith("-")) {
217 // check for options that require arguments
218 if (arg.equals("-N")) {
219 if (i < args.length) {
220 em.numNodes = new Integer(args[i++]).intValue();
222 } else if (arg.equals("-T")) {
223 if (i < args.length) {
224 em.numThreads = new Integer(args[i++]).intValue();
226 } else if (arg.equals("-d")) {
227 if (i < args.length) {
228 em.numDegree = new Integer(args[i++]).intValue();
230 } else if (arg.equals("-i")) {
231 if (i < args.length) {
232 em.numIter = new Integer(args[i++]).intValue();
234 } else if (arg.equals("-p")) {
235 em.printResult = true;
236 } else if (arg.equals("-m")) {
238 } else if (arg.equals("-h")) {
243 if (em.numNodes == 0 || em.numDegree == 0)
248 * The usage routine which describes the program options.
252 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
253 System.printString(" -N the number of nodes\n");
254 System.printString(" -T the number of threads\n");
255 System.printString(" -d the out-degree of each node\n");
256 System.printString(" -i the number of iterations\n");
257 System.printString(" -p (print detailed results\n)");
258 System.printString(" -m (print informative messages)\n");
259 System.printString(" -h (this message)\n");