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++) {
47 Node prev = bg.eNodes;
49 for(int j = 0; j<lowerlimit; j++){
53 for(int j = lowerlimit; j<=upperlimit; j++) {
55 for (int k = 0; k < n.fromCount; k++) {
56 n.value -= n.coeffs[k] * n.fromNodes[k].value;
60 Barrier.enterBarrier(mybarr);
65 for(int j = 0; j<lowerlimit; j++){
69 for(int j = lowerlimit; j<=upperlimit; j++) {
71 for (int k = 0; k < n.fromCount; k++) {
72 n.value -= n.coeffs[k] * n.fromNodes[k].value;
76 Barrier.enterBarrier(mybarr);
81 * The number of nodes (E and H)
85 * The out-degree of each node.
87 private int numDegree;
89 * The number of compute iterations
93 * Should we print the results and other runtime messages
95 private boolean printResult;
97 * Print information messages?
99 private boolean printMsgs;
102 * The main roitine that creates the irregular, linked data structure
103 * that represents the electric and magnetic fields and propagates the
104 * waves through the graph.
105 * @param args the command line arguments
107 public static void main(String args[])
109 Random rand = new Random(783);
110 Em3d em = new Em3d();
111 em.parseCmdLine(args, em);
113 System.out.println("Initializing em3d random graph...");
114 long start0 = System.currentTimeMillis();
115 BiGraph graph1 = new BiGraph();
117 Barrier mybarr = new Barrier(num_threads);
118 BiGraph graph = graph1.create(em.numNodes, em.numDegree, em.printResult, rand);
120 long end0 = System.currentTimeMillis();
122 // compute a single iteration of electro-magnetic propagation
124 System.out.println("Propagating field values for " + em.numIter +
126 long start1 = System.currentTimeMillis();
127 Em3d[] em3d = new Em3d[num_threads];
128 //em3d[0] = new Em3d(graph, 1, em.numNodes, em.numIter, mybarr);
129 em3d[0] = new Em3d(graph, 1, em.numNodes/2, em.numIter, mybarr);
130 em3d[1] = new Em3d(graph, (em.numNodes/2)+1, em.numNodes, em.numIter, mybarr);
131 for(int i = 0; i<num_threads; i++) {
134 for(int i = 0; i<num_threads; i++) {
137 } catch (InterruptedException e) {}
139 long end1 = System.currentTimeMillis();
141 // print current field values
142 if (em.printResult) {
143 System.out.println(graph);
147 System.out.println("EM3D build time "+ (end0 - start0)/1000.0);
148 System.out.println("EM3D compute time " + (end1 - start1)/1000.0);
149 System.out.println("EM3D total time " + (end1 - start0)/1000.0);
151 System.out.println("Done!");
156 * Parse the command line options.
157 * @param args the command line options.
160 public void parseCmdLine(String args[], Em3d em)
165 while (i < args.length && args[i].startsWith("-")) {
168 // check for options that require arguments
169 if (arg.equals("-n")) {
170 if (i < args.length) {
171 em.numNodes = new Integer(args[i++]).intValue();
173 } else if (arg.equals("-d")) {
174 if (i < args.length) {
175 em.numDegree = new Integer(args[i++]).intValue();
177 } else if (arg.equals("-i")) {
178 if (i < args.length) {
179 em.numIter = new Integer(args[i++]).intValue();
181 } else if (arg.equals("-p")) {
182 em.printResult = true;
183 } else if (arg.equals("-m")) {
185 } else if (arg.equals("-h")) {
189 if (em.numNodes == 0 || em.numDegree == 0)
194 * The usage routine which describes the program options.
198 System.out.println("usage: java Em3d -n <nodes> -d <degree> [-p] [-m] [-h]");
199 System.out.println(" -n the number of nodes");
200 System.out.println(" -d the out-degree of each node");
201 System.out.println(" -i the number of iterations");
202 System.out.println(" -p (print detailed results)");
203 System.out.println(" -m (print informative messages)");
204 System.out.println(" -h (this message)");