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;
68 for (int i = 0; i < iteration; i++) {
74 for(int j = 0; j<lowerlimit; j++){
78 for(int j = lowerlimit; j<=upperlimit; j++) {
80 for (int k = 0; k < n.fromCount; k++) {
81 n.value -= n.coeffs[k] * n.fromNodes[k].value;
85 Barrier.enterBarrier(mybarr);
93 for(int j = 0; j<lowerlimit; j++){
97 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;
104 Barrier.enterBarrier(mybarr);
110 * The main roitine that creates the irregular, linked data structure
111 * that represents the electric and magnetic fields and propagates the
112 * waves through the graph.
113 * @param args the command line arguments
115 public static void main(String args[])
119 em = global new Em3d();
121 Em3d.parseCmdLine(args, em);
123 boolean printMsgs, printResult;
126 printMsgs = em.printMsgs;
127 numIter = em.numIter;
128 printResult = em.printResult;
131 System.printString("Initializing em3d random graph...");
132 long start0 = System.currentTimeMillis();
134 System.printString("DEBUG -> numThreads = " + numThreads);
137 mybarr = global new Barrier(numThreads);
143 rand = global new Random(783);
146 graph1 = global new BiGraph();
147 graph = global new BiGraph();
148 graph = graph1.create(em.numNodes, em.numDegree, em.printResult, rand);
151 long end0 = System.currentTimeMillis();
153 // compute a single iteration of electro-magnetic propagation
155 System.printString("Propagating field values for " + numIter +
157 long start1 = System.currentTimeMillis();
160 em3d = global new Em3d[numThreads];
164 em3d[0] = global new Em3d(graph, 1, em.numNodes/2, em.numIter, mybarr);
165 em3d[1] = global new Em3d(graph, (em.numNodes/2)+1, em.numNodes, em.numIter, mybarr);
168 int mid = (128<<24)|(195<<16)|(175<<8)|73;
170 for(int i = 0; i<numThreads; i++) {
177 for(int i = 0; i<numThreads; i++) {
183 long end1 = System.currentTimeMillis();
185 // print current field values
187 //System.printString(graph);
191 System.printString("EM3D build time "+ (long)((end0 - start0)/1000.0));
192 System.printString("EM3D compute time " + (long)((end1 - start1)/1000.0));
193 System.printString("EM3D total time " + (long)((end1 - start0)/1000.0));
195 System.printString("Done!");
200 * Parse the command line options.
201 * @param args the command line options.
204 public static void parseCmdLine(String args[], Em3d em)
209 while (i < args.length && args[i].startsWith("-")) {
212 // check for options that require arguments
213 if (arg.equals("-n")) {
214 if (i < args.length) {
216 em.numNodes = new Integer(args[i++]).intValue();
219 } else if (arg.equals("-d")) {
220 if (i < args.length) {
222 em.numDegree = new Integer(args[i++]).intValue();
225 } else if (arg.equals("-i")) {
226 if (i < args.length) {
228 em.numIter = global new Integer(args[i++]).intValue();
231 } else if (arg.equals("-p")) {
233 em.printResult = true;
235 } else if (arg.equals("-m")) {
239 } else if (arg.equals("-h")) {
244 //if (em.numNodes == 0 || em.numDegree == 0)
249 * The usage routine which describes the program options.
253 System.printString("usage: java Em3d -n <nodes> -d <degree> [-p] [-m] [-h]");
254 System.printString(" -n the number of nodes");
255 System.printString(" -d the out-degree of each node");
256 System.printString(" -i the number of iterations");
257 System.printString(" -p (print detailed results)");
258 System.printString(" -m (print informative messages)");
259 System.printString(" -h (this message)");