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;
53 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr) {
55 this.lowerlimit = lowerlimit;
56 this.upperlimit = upperlimit;
57 this.numIter = numIter;
74 for(int j = 0; j<lowerlimit; j++){
75 enodebase = enodebase.next;
76 hnodebase = hnodebase.next;
80 for (int i = 0; i < iteration; i++) {
84 for(int j = lowerlimit; j<upperlimit; j++) {
85 for (int k = 0; k < n.fromCount; k++) {
86 n.value -= n.coeffs[k] * n.fromNodes[k].value;
92 Barrier.enterBarrier(barr);
93 System.clearPrefetchCache();
98 for(int j = lowerlimit; j<upperlimit; j++) {
99 for (int k = 0; k < n.fromCount; k++) {
100 n.value -= n.coeffs[k] * n.fromNodes[k].value;
105 Barrier.enterBarrier(barr);
106 System.clearPrefetchCache();
111 * The main roitine that creates the irregular, linked data structure
112 * that represents the electric and magnetic fields and propagates the
113 * waves through the graph.
114 * @param args the command line arguments
116 public static void main(String args[]) {
117 Em3d em = new Em3d();
118 Em3d.parseCmdLine(args, em);
120 System.printString("Initializing em3d random graph...\n");
121 long start0 = System.currentTimeMillis();
123 int[] mid = new int[numThreads];
124 mid[0] = (128<<24)|(195<<16)|(175<<8)|78;
125 mid[1] = (128<<24)|(195<<16)|(175<<8)|79;
126 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
129 mybarr = global new Barrier(numThreads);
132 Random rand = new Random(783);
134 graph = BiGraph.create(em.numNodes, em.numDegree, em.printResult, rand);
137 long end0 = System.currentTimeMillis();
139 // compute a single iteration of electro-magnetic propagation
141 System.printString("Propagating field values for " + em.numIter +
142 " iteration(s)...\n");
143 long start1 = System.currentTimeMillis();
146 em3d = global new Em3d[numThreads];
147 em3d[0] = global new Em3d(graph, 0, em.numNodes/2, em.numIter, mybarr);
148 em3d[1] = global new Em3d(graph, (em.numNodes/2) + 1, em.numNodes, em.numIter, mybarr);
152 for(int i = 0; i<numThreads; i++) {
159 for(int i = 0; i<numThreads; i++) {
165 long end1 = System.currentTimeMillis();
167 // print current field values
168 if (em.printResult) {
169 StringBuffer retval = new StringBuffer();
172 dvalue = graph.hNodes.value;
174 int intvalue = (int)dvalue;
178 System.printString("EM3D build time "+ (long)((end0 - start0)/1000.0) + "\n");
179 System.printString("EM3D compute time " + (long)((end1 - start1)/1000.0) + "\n");
180 System.printString("EM3D total time " + (long)((end1 - start0)/1000.0) + "\n");
182 System.printString("Done!"+ "\n");
187 * Parse the command line options.
188 * @param args the command line options.
191 public static void parseCmdLine(String args[], Em3d em)
196 while (i < args.length && args[i].startsWith("-")) {
199 // check for options that require arguments
200 if (arg.equals("-N")) {
201 if (i < args.length) {
202 em.numNodes = new Integer(args[i++]).intValue();
204 } else if (arg.equals("-d")) {
205 if (i < args.length) {
206 em.numDegree = new Integer(args[i++]).intValue();
208 } else if (arg.equals("-i")) {
209 if (i < args.length) {
210 em.numIter = new Integer(args[i++]).intValue();
212 } else if (arg.equals("-p")) {
213 em.printResult = true;
214 } else if (arg.equals("-m")) {
216 } else if (arg.equals("-h")) {
221 if (em.numNodes == 0 || em.numDegree == 0)
226 * The usage routine which describes the program options.
230 System.printString("usage: java Em3d -N <nodes> -d <degree> [-p] [-m] [-h]\n");
231 System.printString(" -N the number of nodes\n");
232 System.printString(" -d the out-degree of each node\n");
233 System.printString(" -i the number of iterations\n");
234 System.printString(" -p (print detailed results\n)");
235 System.printString(" -m (print informative messages)\n");
236 System.printString(" -h (this message)\n");