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;
63 barr = new Barrier("128.195.175.84");
67 random = new Random(lowerlimit);
71 //This is going to conflict badly...Minimize work here
72 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
74 Barrier.enterBarrier(barr);
75 System.clearPrefetchCache();
78 //initialize the eNodes
79 bg.initializeNodes(bg.eNodes, bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, degree, random, threadindex);
81 Barrier.enterBarrier(barr);
84 //initialize the hNodes
85 bg.initializeNodes(bg.hNodes, bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, degree, random, threadindex);
87 Barrier.enterBarrier(barr);
90 bg.makeFromNodes(bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, random);
92 Barrier.enterBarrier(barr);
95 bg.makeFromNodes(bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, random);
97 Barrier.enterBarrier(barr);
100 for (int i = 0; i < iteration; i++) {
103 for(int j = lowerlimit; j<upperlimit; j++) {
104 Node n = bg.eNodes[j];
106 for (int k = 0; k < n.fromCount; k++) {
107 n.value -= n.coeffs[k] * n.fromNodes[k].value;
112 Barrier.enterBarrier(barr);
116 for(int j = lowerlimit; j<upperlimit; j++) {
117 Node n = bg.hNodes[j];
118 for (int k = 0; k < n.fromCount; k++) {
119 n.value -= n.coeffs[k] * n.fromNodes[k].value;
123 Barrier.enterBarrier(barr);
128 * The main roitine that creates the irregular, linked data structure
129 * that represents the electric and magnetic fields and propagates the
130 * waves through the graph.
131 * @param args the command line arguments
133 public static void main(String args[]) {
134 Em3d em = new Em3d();
135 Em3d.parseCmdLine(args, em);
137 System.printString("Initializing em3d random graph...\n");
138 long start0 = System.currentTimeMillis();
139 int numThreads = em.numThreads;
140 int[] mid = new int[8];
141 mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dw-10
142 mid[1] = (128<<24)|(195<<16)|(136<<8)|163; //dw-11
143 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dw-12
144 mid[3] = (128<<24)|(195<<16)|(136<<8)|165; //dw-13
145 mid[4] = (128<<24)|(195<<16)|(136<<8)|166; //dw-14
146 mid[5] = (128<<24)|(195<<16)|(136<<8)|167; //dw-15
147 mid[6] = (128<<24)|(195<<16)|(136<<8)|168; //dw-16
148 mid[7] = (128<<24)|(195<<16)|(136<<8)|169; //dw-17
150 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
151 BarrierServer mybarr;
155 // initialization step 1: allocate BiGraph
156 // System.printString( "Allocating BiGraph.\n" );
159 mybarr = global new BarrierServer(numThreads);
160 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
162 mybarr.start(mid[0]);
165 Em3dWrap[] em3d=new Em3dWrap[numThreads];
166 int increment = em.numNodes/numThreads;
169 // initialization step 2: divide work of allocating nodes
170 // System.printString( "Launching distributed allocation of nodes.\n" );
174 for(int i=0;i<numThreads;i++) {
176 if ((i+1)==numThreads)
177 tmp = global new Em3d(graph, base, em.numNodes, em.numIter, em.numDegree, i);
179 tmp = global new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i);
180 em3d[i]=new Em3dWrap(tmp);
185 boolean waitfordone=true;
193 //System.printString("Starting Barrier run\n");
194 for(int i = 0; i<numThreads; i++) {
195 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");