Sor files with out new barrier implementation
[IRC.git] / Robust / src / Benchmarks / Prefetch / SOR / dsm / SORRunner.java
1 /**************************************************************************
2  *                                                                         *
3  *         Java Grande Forum Benchmark Suite - Thread Version 1.0          *
4  *                                                                         *
5  *                            produced by                                  *
6  *                                                                         *
7  *                  Java Grande Benchmarking Project                       *
8  *                                                                         *
9  *                                at                                       *
10  *                                                                         *
11  *                Edinburgh Parallel Computing Centre                      *
12  *                                                                         *
13  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
14  *                                                                         *
15  *      adapted from SciMark 2.0, author Roldan Pozo (pozo@cam.nist.gov)   *
16  *                                                                         *
17  *      This version copyright (c) The University of Edinburgh, 2001.      *
18  *                         All rights reserved.                            *
19  *                                                                         *
20  **************************************************************************/
21
22 class SORRunner extends Thread {
23
24   int id,num_iterations;
25   double G[][],omega;
26   int nthreads;
27
28   public SORRunner(int id, double omega, double G[][], int num_iterations, int nthreads) {
29     this.id = id;
30     this.omega=omega;
31     this.G=G;
32     this.num_iterations=num_iterations;
33     this.nthreads = nthreads;
34   }
35
36   public void run() {
37     int tmpid, M, N, numthreads;
38     double omega_over_four, one_minus_omega;
39     int numiterations;
40     Barrier barr;
41     barr = new Barrier("128.195.175.79");
42     atomic {
43       System.printString("Inside atomic 1\n");
44       M = G.length;
45       N = G[0].length;
46       omega_over_four = omega * 0.25;
47       one_minus_omega = 1.0 - omega;
48       numthreads = nthreads;
49       tmpid = id;
50       numiterations = num_iterations;
51     }
52
53     // update interior points
54     //
55     int Mm1 = M-1;
56     int Nm1 = N-1;
57
58
59     int ilow, iupper, slice, tslice, ttslice;
60
61     tslice = (Mm1) / 2;
62     ttslice = (tslice + numthreads-1)/numthreads;
63     slice = ttslice*2;
64     ilow=tmpid*slice+1;
65     iupper = ((tmpid+1)*slice)+1;
66     if (iupper > Mm1) iupper =  Mm1+1;
67     if (tmpid == (numthreads-1)) iupper = Mm1+1;
68
69     for (int p=0; p<2*numiterations; p++) {
70       atomic {
71         for (int i=ilow+(p%2); i<iupper; i=i+2) {
72
73           double [] Gi = G[i];
74           double [] Gim1 = G[i-1];
75
76           if(i == 1) { 
77             double [] Gip1 = G[i+1];
78
79             for (int j=1; j<Nm1; j=j+2){
80               Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
81                   + Gi[j+1]) + one_minus_omega * Gi[j];
82
83             }
84           } else if (i == Mm1) {
85
86             double [] Gim2 = G[i-2];
87
88             for (int j=1; j<Nm1; j=j+2){
89               if((j+1) != Nm1) {
90                 Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
91                     + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
92               }
93             }
94
95           } else {
96
97             double [] Gip1 = G[i+1];
98             double [] Gim2 = G[i-2];
99
100             for (int j=1; j<Nm1; j=j+2){
101               Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
102                   + Gi[j+1]) + one_minus_omega * Gi[j];
103
104               if((j+1) != Nm1) {
105                 Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
106                     + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
107               }
108             }
109           }
110         }
111       } //close atomic
112
113       Barrier.enterBarrier(barr);
114     }//end of for
115   } //end of run()
116 }