do sane array allocation now
authorbdemsky <bdemsky>
Sat, 9 Aug 2008 08:07:15 +0000 (08:07 +0000)
committerbdemsky <bdemsky>
Sat, 9 Aug 2008 08:07:15 +0000 (08:07 +0000)
Robust/src/Benchmarks/Prefetch/SOR/dsm/JGFSORBench.java
Robust/src/Benchmarks/Prefetch/SOR/dsm/SORRunner.java
Robust/src/Benchmarks/Prefetch/SOR/dsm/SORWrap.java [new file with mode: 0644]
Robust/src/Benchmarks/Prefetch/SOR/dsm/makefile

index 30cef0144996e1cd5f279b57fdafb3755187315b..c4cae02848beb2694ec62d0c41c8db2954ae5e2a 100644 (file)
@@ -24,7 +24,6 @@ public class JGFSORBench {
   int JACOBI_NUM_ITER;
   long RANDOM_SEED;
   public int nthreads;
-  Random R;
   public double Gtotal;
 
   public JGFSORBench(int nthreads){
@@ -35,7 +34,6 @@ public class JGFSORBench {
     datasizes[2] = 2000;
     JACOBI_NUM_ITER = 100;
     RANDOM_SEED = 10101010;
-    R = global new Random(RANDOM_SEED);
     Gtotal = 0.0;
   }
 
@@ -46,7 +44,6 @@ public class JGFSORBench {
   public static void JGFkernel(JGFSORBench sor) {
     int numthreads, datasize;
     BarrierServer mybarr;
-    Random rand;
 
     int[] mid = new int[4];
     mid[0] = (128<<24)|(195<<16)|(175<<8)|79;
@@ -54,43 +51,34 @@ public class JGFSORBench {
     mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
     mid[3] = (128<<24)|(195<<16)|(175<<8)|69;
 
+    double[][] G;
+    int num_iterations;
+
     atomic {
       numthreads = sor.nthreads;
-      rand = sor.R;
       datasize = sor.datasizes[sor.size];
       mybarr = global new BarrierServer(numthreads);
+      G =  global new double[datasize][];
+      num_iterations = sor.JACOBI_NUM_ITER;
     }
     mybarr.start(mid[0]);
 
-    double[][] G;
-    int M, N;
-    atomic {
-      G = sor.RandomMatrix(datasize, datasize, rand);
-      M = G.length;
-      N = G[0].length;
-    }
     double omega = 1.25;
-    int num_iterations;
-    atomic {
-      num_iterations = sor.JACOBI_NUM_ITER;
-    }
-
     double omega_over_four = omega * 0.25;
     double one_minus_omega = 1.0 - omega;
 
     // update interior points
     //
-    int Mm1 = M-1;
-    int Nm1 = N-1;
-
     //spawn threads
-    SORRunner[] thobjects;
+
+    SORWrap[] thobjects = new SORWrap[numthreads];
+
     atomic {
-      thobjects = global new SORRunner[numthreads];
+       for(int i=0;i<numthreads;i++) {
+           thobjects[i] =  new SORWrap(global new SORRunner(i,omega,G,num_iterations,numthreads));
+       }
     }
 
-    //JGFInstrumentor.startTimer("Section2:SOR:Kernel", instr.timers); 
-
     boolean waitfordone=true;
     while(waitfordone) {
       atomic {
@@ -99,50 +87,24 @@ public class JGFSORBench {
       }
     }
 
-    SORRunner tmp;
-    for(int i=1;i<numthreads;i++) {
-      atomic {
-        thobjects[i] =  global new SORRunner(i,omega,G,num_iterations,numthreads);
-        tmp = thobjects[i];
-      }
-      tmp.start(mid[i]);
-    }
-    atomic {
-      thobjects[0] =  global new SORRunner(0,omega,G,num_iterations,numthreads);
-      tmp = thobjects[0];
+    for(int i=0;i<numthreads;i++) {
+       thobjects[i].sor.start(mid[i]);
     }
-    tmp.start(mid[0]);
-    tmp.join();
 
-    for(int i=1;i<numthreads;i++) {
-      atomic {
-        tmp = thobjects[i];
-      }
-      tmp.join();
+    for(int i=0;i<numthreads;i++) {
+      thobjects[i].sor.join();
     }
 
     //JGFInstrumentor.stopTimer("Section2:SOR:Kernel", instr.timers);
     atomic {
-      for (int i=1; i<Nm1; i++) {
-        for (int j=1; j<Nm1; j++) {
-          sor.Gtotal += G[i][j];
-        }
-      }               
+       for (int i=1; i<G.length-1; i++) {
+           for (int j=1; j<G.length-1; j++) {
+               sor.Gtotal += G[i][j];
+           }
+       }               
     }
   }
 
-  public double[][] RandomMatrix(int M, int N, Random R)
-  {
-    double A[][] = global new double[M][N];
-
-    for (int i=0; i<N; i++)
-      for (int j=0; j<N; j++)
-      {
-        A[i][j] = R.nextDouble() * 1e-6;
-      }      
-    return A;
-  }
-
   public int JGFvalidate(){
 
     double refval[];
@@ -154,8 +116,6 @@ public class JGFSORBench {
     long l = (long) refval[size] * 1000000;
     long r = (long) Gtotal * 1000000;
     if (l != r ){
-      //System.printString("Validation failed");
-      //System.printString("Gtotal = " + (long) Gtotal * 1000000 + "  " +(long) dev * 1000000 + "  " + size);
       return 1;
     } else {
       return 0;
index 954aa1ce326536b89bfbed4340786561fb5b668e..05ff5f9e2926d23900d3719d126f7a9327e8fdfe 100644 (file)
@@ -39,32 +39,45 @@ class SORRunner extends Thread {
     int numiterations;
     Barrier barr;
     barr = new Barrier("128.195.175.79");
+    int ilow, iupper, slice, tslice, ttslice, Mm1, Nm1;
+
     atomic {
       System.printString("Inside atomic 1\n");
-      M = G.length;
-      N = G[0].length;
+      N = M = G.length;
+      
       omega_over_four = omega * 0.25;
       one_minus_omega = 1.0 - omega;
       numthreads = nthreads;
       tmpid = id;
       numiterations = num_iterations;
+      Mm1 = M-1;
+      Nm1 = N-1;
+      tslice = (Mm1) / 2;
+      ttslice = (tslice + numthreads-1)/numthreads;
+      slice = ttslice*2;
+      ilow=tmpid*slice+1;
+      iupper = ((tmpid+1)*slice)+1;
+      if (iupper > Mm1) iupper =  Mm1+1;
+      if (tmpid == (numthreads-1)) iupper = Mm1+1;
+      for(int i=ilow;i<iupper;i++) {
+         G[i]=global new double[N];
+      }
+    }
+
+    Barrier.enterBarrier(barr);
+    atomic {
+       Random rand=new Random();
+       for(int i=ilow;i<iupper;i++) {
+           double[] R=G[i];
+           for(int j=0;j<M;j++)
+               R[j]=rand.nextDouble() * 1e-6;
+       }
     }
+    Barrier.enterBarrier(barr);
 
     // update interior points
     //
-    int Mm1 = M-1;
-    int Nm1 = N-1;
-
-
-    int ilow, iupper, slice, tslice, ttslice;
 
-    tslice = (Mm1) / 2;
-    ttslice = (tslice + numthreads-1)/numthreads;
-    slice = ttslice*2;
-    ilow=tmpid*slice+1;
-    iupper = ((tmpid+1)*slice)+1;
-    if (iupper > Mm1) iupper =  Mm1+1;
-    if (tmpid == (numthreads-1)) iupper = Mm1+1;
 
     for (int p=0; p<2*numiterations; p++) {
       atomic {
diff --git a/Robust/src/Benchmarks/Prefetch/SOR/dsm/SORWrap.java b/Robust/src/Benchmarks/Prefetch/SOR/dsm/SORWrap.java
new file mode 100644 (file)
index 0000000..5606094
--- /dev/null
@@ -0,0 +1,9 @@
+public class SORWrap {
+    public global SORRunner sor;
+    public SORWrap() {
+    }
+
+    public SORWrap(SORRunner e) {
+       sor=e;
+    }
+}
\ No newline at end of file
index a2b55b5b2ceba7152ba04f8c1a2561a5d970640c..57e526a0aa06934ce05c959d2b9303b4f8e29398 100644 (file)
@@ -3,7 +3,8 @@ SRC=${MAINCLASS}.java \
        JGFSORBench.java \
        JGFInstrumentor.java \
        JGFTimer.java \
-       SORRunner.java 
+       SORRunner.java \
+       SORWrap.java
 FLAGS=-dsm -prefetch -optimize -excprefetch JGFSORBench.JGFSORBench -excprefetch JGFSORBenchSizeA.main -excprefetch JGFSORBench.RandomMatrix -excprefetch JGFSORBench.init_sync -excprefetch JGFSORBench.JGFkernel -mainclass ${MAINCLASS} -trueprob 0.88
 FLAGS2=-dsm -optimize -mainclass ${MAINCLASS}