* 1993, pages 262-273.
* </cite>
**/
-public class Em3d extends Thread
-{
+public class Em3d extends Thread {
/**
* The number of nodes (E and H)
* Should we print the results and other runtime messages
**/
private boolean printResult;
- /**
- * Print information messages?
- **/
+ /**
+ * Print information messages?
+ **/
private boolean printMsgs;
+ int threadindex;
+ int numThreads;
+
BiGraph bg;
int upperlimit;
int lowerlimit;
- Barrier mybarr;
-
- public Em3d() {
- numNodes = 0;
- numDegree = 0;
- numIter = 1;
- printResult = false;
- printMsgs = false;
- }
+ public Em3d() {
+ }
- public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, Barrier mybarr) {
+ public Em3d(BiGraph bg, int lowerlimit, int upperlimit, int numIter, int numDegree, int threadindex) {
this.bg = bg;
this.lowerlimit = lowerlimit;
this.upperlimit = upperlimit;
this.numIter = numIter;
- this.mybarr = mybarr;
+ this.numDegree = numDegree;
+ this.threadindex=threadindex;
}
public void run() {
int iteration;
Barrier barr;
- Node enodebase;
- Node hnodebase;
+ int degree;
+ Random random;
+ String hname;
+ barr = new Barrier("128.195.175.79");
atomic {
- iteration = numIter;
- barr=mybarr;
+ iteration = numIter;
+ degree = numDegree;
+ random = new Random(lowerlimit);
}
+
atomic {
- enodebase=bg.eNodes;
- hnodebase=bg.hNodes;
- for(int j = 0; j<lowerlimit; j++){
- enodebase = enodebase.next;
- hnodebase = hnodebase.next;
- }
+ //This is going to conflict badly...Minimize work here
+ bg.allocateNodes ( lowerlimit, upperlimit, threadindex);
}
+ Barrier.enterBarrier(barr);
+ System.clearPrefetchCache();
+ atomic {
+ //initialize the eNodes
+ bg.initializeNodes(bg.eNodes, bg.hNodes, lowerlimit, upperlimit, degree, random, threadindex);
+ }
+ Barrier.enterBarrier(barr);
+
+ atomic {
+ //initialize the hNodes
+ bg.initializeNodes(bg.hNodes, bg.eNodes, lowerlimit, upperlimit, degree, random, threadindex);
+ }
+ Barrier.enterBarrier(barr);
+
+ atomic {
+ bg.makeFromNodes(bg.hNodes, lowerlimit, upperlimit, random);
+ }
+ Barrier.enterBarrier(barr);
+
+ atomic {
+ bg.makeFromNodes(bg.eNodes, lowerlimit, upperlimit, random);
+ }
+ Barrier.enterBarrier(barr);
+
+ //Do the computation
for (int i = 0; i < iteration; i++) {
- /* for eNodes */
+ /* for eNodes */
atomic {
- Node n = enodebase;
for(int j = lowerlimit; j<upperlimit; j++) {
+ Node n = bg.eNodes[j];
+
for (int k = 0; k < n.fromCount; k++) {
n.value -= n.coeffs[k] * n.fromNodes[k].value;
}
- n = n.next;
}
}
Barrier.enterBarrier(barr);
- System.clearPrefetchCache();
-
+
/* for hNodes */
atomic {
- Node n = hnodebase;
for(int j = lowerlimit; j<upperlimit; j++) {
+ Node n = bg.hNodes[j];
for (int k = 0; k < n.fromCount; k++) {
n.value -= n.coeffs[k] * n.fromNodes[k].value;
}
- n=n.next;
}
}
Barrier.enterBarrier(barr);
- System.clearPrefetchCache();
}
}
if (em.printMsgs)
System.printString("Initializing em3d random graph...\n");
long start0 = System.currentTimeMillis();
- int numThreads = 2;
- int[] mid = new int[numThreads];
- mid[0] = (128<<24)|(195<<16)|(175<<8)|78;
- mid[1] = (128<<24)|(195<<16)|(175<<8)|79;
+ int numThreads = em.numThreads;
+ int[] mid = new int[4];
+ mid[0] = (128<<24)|(195<<16)|(175<<8)|79;//dw-1
+ mid[1] = (128<<24)|(195<<16)|(175<<8)|73;//dw-2
+ mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
+ mid[3] = (128<<24)|(195<<16)|(175<<8)|69;
+
System.printString("DEBUG -> numThreads = " + numThreads+"\n");
- Barrier mybarr;
- atomic {
- mybarr = global new Barrier(numThreads);
- }
+ BarrierServer mybarr;
BiGraph graph;
- Random rand = new Random(783);
+
+
+ // initialization step 1: allocate BiGraph
+ // System.printString( "Allocating BiGraph.\n" );
+
atomic {
- graph = BiGraph.create(em.numNodes, em.numDegree, em.printResult, rand);
+ mybarr = global new BarrierServer(numThreads);
+ graph = BiGraph.create(em.numNodes, em.numDegree, numThreads);
}
+ mybarr.start(mid[0]);
- long end0 = System.currentTimeMillis();
- // compute a single iteration of electro-magnetic propagation
- if (em.printMsgs)
- System.printString("Propagating field values for " + em.numIter +
- " iteration(s)...\n");
- long start1 = System.currentTimeMillis();
- Em3d[] em3d;
+ Em3dWrap[] em3d=new Em3dWrap[numThreads];
+ int increment = em.numNodes/numThreads;
+
+
+ // initialization step 2: divide work of allocating nodes
+ // System.printString( "Launching distributed allocation of nodes.\n" );
+
atomic {
- em3d = global new Em3d[numThreads];
- em3d[0] = global new Em3d(graph, 0, em.numNodes/2, em.numIter, mybarr);
- em3d[1] = global new Em3d(graph, (em.numNodes/2) + 1, em.numNodes, em.numIter, mybarr);
+ int base=0;
+ for(int i=0;i<numThreads;i++) {
+ Em3d tmp;
+ if ((i+1)==numThreads)
+ tmp = global new Em3d(graph, base, em.numNodes, em.numIter, em.numDegree, i);
+ else
+ tmp = global new Em3d(graph, base, base+increment, em.numIter, em.numDegree, i);
+ em3d[i]=new Em3dWrap(tmp);
+ base+=increment;
+ }
}
- Em3d tmp;
- for(int i = 0; i<numThreads; i++) {
- atomic {
- tmp = em3d[i];
- }
- tmp.start(mid[i]);
+ boolean waitfordone=true;
+ while(waitfordone) {
+ atomic {
+ if (mybarr.done)
+ waitfordone=false;
+ }
}
+ //System.printString("Starting Barrier run\n");
for(int i = 0; i<numThreads; i++) {
- atomic {
- tmp = em3d[i];
- }
- tmp.join();
- }
- long end1 = System.currentTimeMillis();
-
- // print current field values
- if (em.printResult) {
- StringBuffer retval = new StringBuffer();
- double dvalue;
- atomic {
- dvalue = graph.hNodes.value;
- }
- int intvalue = (int)dvalue;
+ em3d[i].em3d.start(mid[i]);
}
-
- if (em.printMsgs) {
- System.printString("EM3D build time "+ (long)((end0 - start0)/1000.0) + "\n");
- System.printString("EM3D compute time " + (long)((end1 - start1)/1000.0) + "\n");
- System.printString("EM3D total time " + (long)((end1 - start0)/1000.0) + "\n");
+ for(int i = 0; i<numThreads; i++) {
+ em3d[i].em3d.join();
}
System.printString("Done!"+ "\n");
}
if (i < args.length) {
em.numNodes = new Integer(args[i++]).intValue();
}
+ } else if (arg.equals("-T")) {
+ if (i < args.length) {
+ em.numThreads = new Integer(args[i++]).intValue();
+ }
} else if (arg.equals("-d")) {
if (i < args.length) {
em.numDegree = new Integer(args[i++]).intValue();
**/
public void usage()
{
- System.printString("usage: java Em3d -N <nodes> -d <degree> [-p] [-m] [-h]\n");
+ System.printString("usage: java Em3d -T <threads> -N <nodes> -d <degree> [-p] [-m] [-h]\n");
System.printString(" -N the number of nodes\n");
+ System.printString(" -T the number of threads\n");
System.printString(" -d the out-degree of each node\n");
System.printString(" -i the number of iterations\n");
System.printString(" -p (print detailed results\n)");