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.
19 * The number of nodes (E and H)
23 * The out-degree of each node.
25 private int numDegree;
27 * The number of compute iterations
31 * Should we print the results and other runtime messages
33 private boolean printResult;
35 * Print information messages?
37 private boolean printMsgs;
48 public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, int numDegree, int threadindex) {
50 this.lowerlimit = lowerlimit;
51 this.upperlimit = upperlimit;
52 this.numIter = numIter;
53 this.numDegree = numDegree;
54 this.threadindex=threadindex;
65 random = new Random(lowerlimit);
67 //This is going to conflict badly...Minimize work here
68 bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
71 //initialize the eNodes
72 bg.initializeNodes(bg.eNodes, bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, degree, random, threadindex);
74 //initialize the hNodes
75 bg.initializeNodes(bg.hNodes, bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, degree, random, threadindex);
77 bg.makeFromNodes(bg.hNodes, bg.hreversetable, lowerlimit, upperlimit, random);
79 bg.makeFromNodes(bg.eNodes, bg.ereversetable, lowerlimit, upperlimit, random);
82 for (int i = 0; i < iteration; i++) {
84 for(int j = lowerlimit; j<upperlimit; j++) {
85 Node n = bg.eNodes[j];
87 for (int k = 0; k < n.fromCount; k++) {
88 n.value -= n.coeffs[k] * n.fromNodes[k].value;
94 for(int j = lowerlimit; j<upperlimit; j++) {
95 Node n = bg.hNodes[j];
96 for (int k = 0; k < n.fromCount; k++) {
97 n.value -= n.coeffs[k] * n.fromNodes[k].value;
104 * The main roitine that creates the irregular, linked data structure
105 * that represents the electric and magnetic fields and propagates the
106 * waves through the graph.
107 * @param args the command line arguments
109 public static void main(String args[]) {
110 Em3d em = new Em3d();
111 Em3d.parseCmdLine(args, em);
113 System.printString("Initializing em3d random graph...\n");
114 long start0 = System.currentTimeMillis();
115 int numThreads = em.numThreads;
117 System.printString("DEBUG -> numThreads = " + numThreads+"\n");
121 // initialization step 1: allocate BiGraph
122 // System.printString( "Allocating BiGraph.\n" );
124 graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
127 Em3dWrap[] em3d=new Em3dWrap[numThreads];
128 int increment = em.numNodes/numThreads;
131 // initialization step 2: divide work of allocating nodes
132 // System.printString( "Launching distributed allocation of nodes.\n" );
135 for(int i=0;i<numThreads;i++) {
137 if ((i+1)==numThreads)
138 tmp = new Em3d(graph, base, em.numNodes, em.numIter, em.numDegree, i);
140 tmp = new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i);
141 em3d[i]=new Em3dWrap(tmp);
145 //System.printString("Starting Barrier run\n");
146 for(int i = 0; i<numThreads; i++) {
150 System.printString("Done!"+ "\n");
155 * Parse the command line options.
156 * @param args the command line options.
159 public static void parseCmdLine(String args[], Em3d em)
164 while (i < args.length && args[i].startsWith("-")) {
167 // check for options that require arguments
168 if (arg.equals("-N")) {
169 if (i < args.length) {
170 em.numNodes = new Integer(args[i++]).intValue();
172 } else if (arg.equals("-T")) {
173 if (i < args.length) {
174 em.numThreads = new Integer(args[i++]).intValue();
176 } else if (arg.equals("-d")) {
177 if (i < args.length) {
178 em.numDegree = new Integer(args[i++]).intValue();
180 } else if (arg.equals("-i")) {
181 if (i < args.length) {
182 em.numIter = new Integer(args[i++]).intValue();
184 } else if (arg.equals("-p")) {
185 em.printResult = true;
186 } else if (arg.equals("-m")) {
188 } else if (arg.equals("-h")) {
193 if (em.numNodes == 0 || em.numDegree == 0)
198 * The usage routine which describes the program options.
202 System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
203 System.printString(" -N the number of nodes\n");
204 System.printString(" -T the number of threads\n");
205 System.printString(" -d the out-degree of each node\n");
206 System.printString(" -i the number of iterations\n");
207 System.printString(" -p (print detailed results\n)");
208 System.printString(" -m (print informative messages)\n");
209 System.printString(" -h (this message)\n");