2 import java.util.Random;
7 * Java implementation of the <tt>em3d</tt> Olden benchmark. This Olden
8 * benchmark models the propagation of electromagnetic waves through
9 * objects in 3 dimensions. It is a simple computation on an irregular
10 * bipartite graph containing nodes representing electric and magnetic
14 * D. Culler, A. Dusseau, S. Goldstein, A. Krishnamurthy, S. Lumetta, T. von
15 * Eicken and K. Yelick. "Parallel Programming in Split-C". Supercomputing
16 * 1993, pages 262-273.
19 public class Em3d extends Thread
36 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr) {
38 this.lowerlimit = lowerlimit;
39 this.upperlimit = upperlimit;
40 this.numIter = numIter;
45 for (int i = 0; i < numIter; i++) {
46 Barrier runBarrier = new Barrier();
48 Node prev = bg.eNodes;
50 for(int j = 0; j<lowerlimit; j++){
54 for(int j = lowerlimit; j<=upperlimit; j++) {
56 for (int k = 0; k < n.fromCount; k++) {
57 n.value -= n.coeffs[k] * n.fromNodes[k].value;
61 runBarrier.enterBarrier(mybarr);
67 for(int j = 0; j<lowerlimit; j++){
71 for(int j = lowerlimit; j<=upperlimit; j++) {
73 for (int k = 0; k < n.fromCount; k++) {
74 n.value -= n.coeffs[k] * n.fromNodes[k].value;
78 runBarrier.enterBarrier(mybarr);
84 * The number of nodes (E and H)
88 * The out-degree of each node.
90 private int numDegree;
92 * The number of compute iterations
96 * Should we print the results and other runtime messages
98 private boolean printResult;
100 * Print information messages?
102 private boolean printMsgs;
105 * The main roitine that creates the irregular, linked data structure
106 * that represents the electric and magnetic fields and propagates the
107 * waves through the graph.
108 * @param args the command line arguments
110 public static void main(String args[])
112 Random rand = new Random(783);
113 Em3d em = new Em3d();
114 em.parseCmdLine(args, em);
116 System.out.println("Initializing em3d random graph...");
117 long start0 = System.currentTimeMillis();
118 BiGraph graph1 = new BiGraph();
120 Barrier mybarr = new Barrier(num_threads);
121 System.out.println("DEBUG -> num_threads = " + num_threads);
122 BiGraph graph = graph1.create(em.numNodes, em.numDegree, em.printResult, rand);
124 long end0 = System.currentTimeMillis();
126 // compute a single iteration of electro-magnetic propagation
128 System.out.println("Propagating field values for " + em.numIter +
130 long start1 = System.currentTimeMillis();
131 Em3d[] em3d = new Em3d[num_threads];
132 //em3d[0] = new Em3d(graph, 1, em.numNodes, em.numIter, mybarr);
133 em3d[0] = new Em3d(graph, 1, em.numNodes/2, em.numIter, mybarr);
134 em3d[1] = new Em3d(graph, (em.numNodes/2)+1, em.numNodes, em.numIter, mybarr);
135 for(int i = 0; i<num_threads; i++) {
138 for(int i = 0; i<num_threads; i++) {
141 } catch (InterruptedException e) {}
143 long end1 = System.currentTimeMillis();
145 // print current field values
146 if (em.printResult) {
147 System.out.println(graph);
151 System.out.println("EM3D build time "+ (end0 - start0)/1000.0);
152 System.out.println("EM3D compute time " + (end1 - start1)/1000.0);
153 System.out.println("EM3D total time " + (end1 - start0)/1000.0);
155 System.out.println("Done!");
160 * Parse the command line options.
161 * @param args the command line options.
164 public void parseCmdLine(String args[], Em3d em)
169 while (i < args.length && args[i].startsWith("-")) {
172 // check for options that require arguments
173 if (arg.equals("-n")) {
174 if (i < args.length) {
175 em.numNodes = new Integer(args[i++]).intValue();
177 } else if (arg.equals("-d")) {
178 if (i < args.length) {
179 em.numDegree = new Integer(args[i++]).intValue();
181 } else if (arg.equals("-i")) {
182 if (i < args.length) {
183 em.numIter = new Integer(args[i++]).intValue();
185 } else if (arg.equals("-p")) {
186 em.printResult = true;
187 } else if (arg.equals("-m")) {
189 } else if (arg.equals("-h")) {
193 if (em.numNodes == 0 || em.numDegree == 0)
198 * The usage routine which describes the program options.
202 System.out.println("usage: java Em3d -n <nodes> -d <degree> [-p] [-m] [-h]");
203 System.out.println(" -n the number of nodes");
204 System.out.println(" -d the out-degree of each node");
205 System.out.println(" -i the number of iterations");
206 System.out.println(" -p (print detailed results)");
207 System.out.println(" -m (print informative messages)");
208 System.out.println(" -h (this message)");