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");
66 System.printString("Inside atomic 1\n");
69 random = new Random(lowerlimit);
73 //This is going to conflict badly...Minimize work here
74 System.printString("Inside atomic 2\n");
75 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
77 Barrier.enterBarrier(barr);
78 System.clearPrefetchCache();
81 //initialize the eNodes
82 System.printString("Inside atomic 3\n");
83 bg.initializeNodes(bg.eNodes, bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, degree, random, threadindex);
85 Barrier.enterBarrier(barr);
88 //initialize the hNodes
89 System.printString("Inside atomic 4\n");
90 bg.initializeNodes(bg.hNodes, bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, degree, random, threadindex);
92 Barrier.enterBarrier(barr);
95 System.printString("Inside atomic 5\n");
96 bg.makeFromNodes(bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, random);
98 Barrier.enterBarrier(barr);
101 System.printString("Inside atomic 6\n");
102 bg.makeFromNodes(bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, random);
104 Barrier.enterBarrier(barr);
107 for (int i = 0; i < iteration; i++) {
110 System.printString("Inside atomic 7\n");
111 for(int j = lowerlimit; j<upperlimit; j++) {
112 Node n = bg.eNodes[j];
114 for (int k = 0; k < n.fromCount; k++) {
115 n.value -= n.coeffs[k] * n.fromNodes[k].value;
120 Barrier.enterBarrier(barr);
124 System.printString("Inside atomic 8\n");
125 for(int j = lowerlimit; j<upperlimit; j++) {
126 Node n = bg.hNodes[j];
127 for (int k = 0; k < n.fromCount; k++) {
128 n.value -= n.coeffs[k] * n.fromNodes[k].value;
132 Barrier.enterBarrier(barr);
137 * The main roitine that creates the irregular, linked data structure
138 * that represents the electric and magnetic fields and propagates the
139 * waves through the graph.
140 * @param args the command line arguments
142 public static void main(String args[]) {
143 Em3d em = new Em3d();
144 Em3d.parseCmdLine(args, em);
146 System.printString("Initializing em3d random graph...\n");
147 long start0 = System.currentTimeMillis();
148 int numThreads = em.numThreads;
149 int[] mid = new int[4];
150 mid[0] = (128<<24)|(195<<16)|(175<<8)|79;//dw-1
151 mid[1] = (128<<24)|(195<<16)|(175<<8)|73;//dw-2
152 mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
153 mid[3] = (128<<24)|(195<<16)|(175<<8)|69;
155 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
156 BarrierServer mybarr;
160 // initialization step 1: allocate BiGraph
161 // System.printString( "Allocating BiGraph.\n" );
164 mybarr = global new BarrierServer(numThreads);
165 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
167 mybarr.start(mid[0]);
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);
184 tmp = global new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i);
185 em3d[i]=new Em3dWrap(tmp);
190 boolean waitfordone=true;
198 //System.printString("Starting Barrier run\n");
199 for(int i = 0; i<numThreads; i++) {
200 em3d[i].em3d.start(mid[i]);
202 for(int i = 0; i<numThreads; i++) {
205 System.printString("Done!"+ "\n");
210 * Parse the command line options.
211 * @param args the command line options.
214 public static void parseCmdLine(String args[], Em3d em)
219 while (i < args.length && args[i].startsWith("-")) {
222 // check for options that require arguments
223 if (arg.equals("-N")) {
224 if (i < args.length) {
225 em.numNodes = new Integer(args[i++]).intValue();
227 } else if (arg.equals("-T")) {
228 if (i < args.length) {
229 em.numThreads = new Integer(args[i++]).intValue();
231 } else if (arg.equals("-d")) {
232 if (i < args.length) {
233 em.numDegree = new Integer(args[i++]).intValue();
235 } else if (arg.equals("-i")) {
236 if (i < args.length) {
237 em.numIter = new Integer(args[i++]).intValue();
239 } else if (arg.equals("-p")) {
240 em.printResult = true;
241 } else if (arg.equals("-m")) {
243 } else if (arg.equals("-h")) {
248 if (em.numNodes == 0 || em.numDegree == 0)
253 * The usage routine which describes the program options.
257 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
258 System.printString(" -N the number of nodes\n");
259 System.printString(" -T the number of threads\n");
260 System.printString(" -d the out-degree of each node\n");
261 System.printString(" -i the number of iterations\n");
262 System.printString(" -p (print detailed results\n)");
263 System.printString(" -m (print informative messages)\n");
264 System.printString(" -h (this message)\n");