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
20 * The number of nodes (E and H)
24 * The out-degree of each node.
26 private int numDegree;
28 * The number of compute iterations
32 * Should we print the results and other runtime messages
34 private boolean printResult;
36 * Print information messages?
38 private boolean printMsgs;
55 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr) {
57 this.lowerlimit = lowerlimit;
58 this.upperlimit = upperlimit;
59 this.numIter = numIter;
72 for (int i = 0; i < iteration; i++) {
75 for(int j = lowerlimit; j<upperlimit; j++) {
76 Node n = bg.eNodes[j];
78 for (int k = 0; k < n.fromCount; k++) {
79 n.value -= n.coeffs[k] * n.fromNodes[k].value;
84 Barrier.enterBarrier(barr);
88 for(int j = lowerlimit; j<upperlimit; j++) {
89 Node n = bg.hNodes[j];
90 for (int k = 0; k < n.fromCount; k++) {
91 n.value -= n.coeffs[k] * n.fromNodes[k].value;
95 Barrier.enterBarrier(barr);
100 * The main roitine that creates the irregular, linked data structure
101 * that represents the electric and magnetic fields and propagates the
102 * waves through the graph.
103 * @param args the command line arguments
105 public static void main(String args[]) {
106 Em3d em = new Em3d();
107 Em3d.parseCmdLine(args, em);
109 System.printString("Initializing em3d random graph...\n");
110 long start0 = System.currentTimeMillis();
111 int numThreads = em.numThreads;
112 int[] mid = new int[4];
113 mid[0] = (128<<24)|(195<<16)|(175<<8)|79;
114 mid[1] = (128<<24)|(195<<16)|(175<<8)|73;
115 mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
116 mid[3] = (128<<24)|(195<<16)|(175<<8)|69;
117 //System.printString("DEBUG -> numThreads = " + numThreads+"\n");
120 Random rand = new Random(783);
123 mybarr = global new Barrier(numThreads);
124 graph = BiGraph.create(em.numNodes, em.numDegree, em.printResult, rand);
127 long end0 = System.currentTimeMillis();
129 // compute a single iteration of electro-magnetic propagation
131 System.printString("Propagating field values for " + em.numIter +
132 " iteration(s)...\n");
133 long start1 = System.currentTimeMillis();
137 em3d = global new Em3d[numThreads];
138 int increment=em.numNodes/numThreads;
140 for(int i=0;i<numThreads;i++) {
141 if ((i+1)==numThreads)
142 em3d[i] = global new Em3d(graph, base, em.numNodes, em.numIter, mybarr);
144 em3d[i] = global new Em3d(graph, base, base+increment, em.numIter, mybarr);
150 for(int i = 0; i<numThreads; i++) {
157 for(int i = 0; i<numThreads; i++) {
163 long end1 = System.currentTimeMillis();
165 // print current field values
166 if (em.printResult) {
167 StringBuffer retval = new StringBuffer();
170 dvalue = graph.hNodes[0].value;
172 int intvalue = (int)dvalue;
176 System.printString("EM3D build time "+ (long)((end0 - start0)/1000.0) + "\n");
177 System.printString("EM3D compute time " + (long)((end1 - start1)/1000.0) + "\n");
178 System.printString("EM3D total time " + (long)((end1 - start0)/1000.0) + "\n");
180 System.printString("Done!"+ "\n");
185 * Parse the command line options.
186 * @param args the command line options.
189 public static void parseCmdLine(String args[], Em3d em)
194 while (i < args.length && args[i].startsWith("-")) {
197 // check for options that require arguments
198 if (arg.equals("-N")) {
199 if (i < args.length) {
200 em.numNodes = new Integer(args[i++]).intValue();
202 } else if (arg.equals("-T")) {
203 if (i < args.length) {
204 em.numThreads = new Integer(args[i++]).intValue();
206 } else if (arg.equals("-d")) {
207 if (i < args.length) {
208 em.numDegree = new Integer(args[i++]).intValue();
210 } else if (arg.equals("-i")) {
211 if (i < args.length) {
212 em.numIter = new Integer(args[i++]).intValue();
214 } else if (arg.equals("-p")) {
215 em.printResult = true;
216 } else if (arg.equals("-m")) {
218 } else if (arg.equals("-h")) {
223 if (em.numNodes == 0 || em.numDegree == 0)
228 * The usage routine which describes the program options.
232 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
233 System.printString(" -N the number of nodes\n");
234 System.printString(" -T the number of threads\n");
235 System.printString(" -d the out-degree of each node\n");
236 System.printString(" -i the number of iterations\n");
237 System.printString(" -p (print detailed results\n)");
238 System.printString(" -m (print informative messages)\n");
239 System.printString(" -h (this message)\n");