rewritten SOR benchmark
[IRC.git] / Robust / src / Benchmarks / Prefetch / SOR / dsm / SORRunner.java
index a4d0087267bd06bebc34ee5a68c0fd96c07d7314..9846a33f88a8f8002a4f18931accbd4c664a8359 100644 (file)
@@ -23,49 +23,67 @@ class SORRunner extends Thread {
 
   int id,num_iterations;
   double G[][],omega;
-  long sync[][];
   int nthreads;
 
-  public SORRunner(int id, double omega, double G[][], int num_iterations,long[][] sync, int nthreads) {
+  public SORRunner(int id, double omega, double G[][], int num_iterations, int nthreads) {
     this.id = id;
     this.omega=omega;
     this.G=G;
     this.num_iterations=num_iterations;
-    this.sync=sync;
     this.nthreads = nthreads;
   }
 
   public void run() {
-
     int tmpid, M, N, numthreads;
     double omega_over_four, one_minus_omega;
+    int numiterations;
+    Barrier barr;
+    barr = new Barrier("128.195.175.79");
+    int ilow, iupper, slice, tslice, ttslice, Mm1, Nm1;
+
     atomic {
-      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;
+      G[0]=global new double[N];
+      for(int i=ilow;i<iupper;i++) {
+        G[i]=global new double[N];
+      }
+    }
+
+    Barrier.enterBarrier(barr);
+    atomic {
+      Random rand=new Random();
+      double[] R = G[0];
+      for(int j=0;j<M;j++)
+        R[j]=rand.nextDouble() * 1e-6;
+      for(int i=ilow;i<iupper;i++) {
+        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;
-
-    atomic {
-      for (int p=0; p<2*num_iterations; p++) {
+    for (int p=0; p<2*numiterations; p++) {
+      atomic {
         for (int i=ilow+(p%2); i<iupper; i=i+2) {
 
           double [] Gi = G[i];
@@ -81,6 +99,29 @@ class SORRunner extends Thread {
             }
           } else if (i == Mm1) {
 
+          } else {
+
+            double [] Gip1 = G[i+1];
+
+            for (int j=1; j<Nm1; j=j+2){
+              Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
+                  + Gi[j+1]) + one_minus_omega * Gi[j];
+
+            }
+          }
+        }
+      } //close atomic
+
+      Barrier.enterBarrier(barr);
+      atomic {
+        for (int i=ilow+(p%2); i<iupper; i=i+2) {
+
+          double [] Gi = G[i];
+          double [] Gim1 = G[i-1];
+
+          if(i == 1) { 
+          } else if (i == Mm1) {
+
             double [] Gim2 = G[i-2];
 
             for (int j=1; j<Nm1; j=j+2){
@@ -92,33 +133,19 @@ class SORRunner extends Thread {
 
           } else {
 
-            double [] Gip1 = G[i+1];
             double [] Gim2 = G[i-2];
 
             for (int j=1; j<Nm1; j=j+2){
-              Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
-                  + Gi[j+1]) + one_minus_omega * Gi[j];
-
               if((j+1) != Nm1) {
                 Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
                     + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
               }
             }
           }
-
         }
+      } //close atomic
 
-        // Signal this thread has done iteration
-        sync[id][0]++;
-
-        // Wait for neighbours;
-        if (id > 0) {
-          while (sync[id-1][0] < sync[id][0]) ;
-        }
-        if (id < nthreads -1) {
-          while (sync[id+1][0] < sync[id][0]) ;
-        }
-      }//end of outer for
-    }//end of atomic
-  }//end of run
+      Barrier.enterBarrier(barr);
+    }//end of for
+  } //end of run()
 }