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.78");
65 //System.printString("Inside run\n");
69 random = new Random(lowerlimit);
73 //System.printString("Here 1\n");
75 //This is going to conflict badly...Minimize work here
76 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
78 Barrier.enterBarrier(barr);
79 System.clearPrefetchCache();
80 //System.printString("Here 2\n");
83 //initialize the eNodes
84 bg.initializeNodes(bg.eNodes, bg.hNodes, lowerlimit, upperlimit, degree, random, threadindex);
86 Barrier.enterBarrier(barr);
87 //System.printString("Here 3\n");
90 //initialize the hNodes
91 bg.initializeNodes(bg.hNodes, bg.eNodes, lowerlimit, upperlimit, degree, random, threadindex);
93 Barrier.enterBarrier(barr);
94 //System.printString("Here 4\n");
97 bg.makeFromNodes(bg.hNodes, lowerlimit, upperlimit, random);
99 Barrier.enterBarrier(barr);
100 //System.printString("Here 5\n");
103 bg.makeFromNodes(bg.eNodes, lowerlimit, upperlimit, random);
105 Barrier.enterBarrier(barr);
106 //System.printString("Here 6\n");
109 for (int i = 0; i < iteration; i++) {
112 for(int j = lowerlimit; j<upperlimit; j++) {
113 Node n = bg.eNodes[j];
115 for (int k = 0; k < n.fromCount; k++) {
116 n.value -= n.coeffs[k] * n.fromNodes[k].value;
121 Barrier.enterBarrier(barr);
123 //System.printString("Here 7\n");
126 for(int j = lowerlimit; j<upperlimit; j++) {
127 Node n = bg.hNodes[j];
128 for (int k = 0; k < n.fromCount; k++) {
129 n.value -= n.coeffs[k] * n.fromNodes[k].value;
133 Barrier.enterBarrier(barr);
134 //System.printString("Here 8\n");
139 * The main roitine that creates the irregular, linked data structure
140 * that represents the electric and magnetic fields and propagates the
141 * waves through the graph.
142 * @param args the command line arguments
144 public static void main(String args[]) {
145 Em3d em = new Em3d();
146 Em3d.parseCmdLine(args, em);
148 System.printString("Initializing em3d random graph...\n");
149 long start0 = System.currentTimeMillis();
150 int numThreads = em.numThreads;
151 int[] mid = new int[4];
155 hostname = global new String[4];
156 hostname[0] = global new String("128.195.175.79");
157 hostname[1] = global new String("128.195.175.73");
158 hostname[2] = global new String("128.195.175.78");
159 hostname[3] = global new String("128.195.175.69");
162 mid[0] = (128<<24)|(195<<16)|(175<<8)|79;//dw-1
163 mid[1] = (128<<24)|(195<<16)|(175<<8)|73;//dw-2
164 mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
165 mid[3] = (128<<24)|(195<<16)|(175<<8)|69;
167 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
168 BarrierServer mybarr;
172 // initialization step 1: allocate BiGraph
173 // System.printString( "Allocating BiGraph.\n" );
176 mybarr = global new BarrierServer(numThreads);
177 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
179 mybarr.start(mid[1]);
182 Em3dWrap[] em3d=new Em3dWrap[numThreads];
183 int increment = em.numNodes/numThreads;
186 // initialization step 2: divide work of allocating nodes
187 // System.printString( "Launching distributed allocation of nodes.\n" );
191 for(int i=0;i<numThreads;i++) {
193 if ((i+1)==numThreads)
194 tmp = global new Em3d(graph, base, em.numNodes, em.numIter, em.numDegree, i);
196 tmp = global new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i);
197 em3d[i]=new Em3dWrap(tmp);
202 boolean waitfordone=true;
212 //TODO check if correct
214 System.printString("Starting Barrier run\n");
215 for(int i = 0; i<numThreads; i++) {
216 em3d[i].em3d.start(mid[i]);
218 for(int i = 0; i<numThreads; i++) {
221 //System.printString("Join Barrier run\n");
223 System.printString("Done!"+ "\n");
228 * Parse the command line options.
229 * @param args the command line options.
232 public static void parseCmdLine(String args[], Em3d em)
237 while (i < args.length && args[i].startsWith("-")) {
240 // check for options that require arguments
241 if (arg.equals("-N")) {
242 if (i < args.length) {
243 em.numNodes = new Integer(args[i++]).intValue();
245 } else if (arg.equals("-T")) {
246 if (i < args.length) {
247 em.numThreads = new Integer(args[i++]).intValue();
249 } else if (arg.equals("-d")) {
250 if (i < args.length) {
251 em.numDegree = new Integer(args[i++]).intValue();
253 } else if (arg.equals("-i")) {
254 if (i < args.length) {
255 em.numIter = new Integer(args[i++]).intValue();
257 } else if (arg.equals("-p")) {
258 em.printResult = true;
259 } else if (arg.equals("-m")) {
261 } else if (arg.equals("-h")) {
266 if (em.numNodes == 0 || em.numDegree == 0)
271 * The usage routine which describes the program options.
275 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
276 System.printString(" -N the number of nodes\n");
277 System.printString(" -T the number of threads\n");
278 System.printString(" -d the out-degree of each node\n");
279 System.printString(" -i the number of iterations\n");
280 System.printString(" -p (print detailed results\n)");
281 System.printString(" -m (print informative messages)\n");
282 System.printString(" -h (this message)\n");