start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / SOR / java / 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   long sync[][];
27   int nthreads;
28
29   public SORRunner(int id, double omega, double G[][], int num_iterations,long[][] sync, int nthreads) {
30     this.id = id;
31     this.omega=omega;
32     this.G=G;
33     this.num_iterations=num_iterations;
34     this.sync=sync;
35     this.nthreads = nthreads;
36   }
37
38   public void run() {
39
40     int M = G.length;
41     int N = G[0].length;
42
43     double omega_over_four = omega * 0.25;
44     double one_minus_omega = 1.0 - omega;
45
46     // update interior points
47     //
48     int Mm1 = M-1;
49     int Nm1 = N-1;
50
51
52     int ilow, iupper, slice, tslice, ttslice;
53
54     tslice = (Mm1) / 2;
55     ttslice = (tslice + nthreads-1)/nthreads;
56     slice = ttslice*2;
57
58     ilow=id*slice+1;
59     iupper = ((id+1)*slice)+1;
60     if (iupper > Mm1) iupper =  Mm1+1;
61     if (id == (nthreads-1)) iupper = Mm1+1;
62
63     for (int p=0; p<2*num_iterations; p++) {
64       for (int i=ilow+(p%2); i<iupper; i=i+2) {
65
66         double [] Gi = G[i];
67         double [] Gim1 = G[i-1];
68
69         if(i == 1) { 
70           double [] Gip1 = G[i+1];
71
72           for (int j=1; j<Nm1; j=j+2){
73             Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
74                 + Gi[j+1]) + one_minus_omega * Gi[j];
75
76           }
77         } else if (i == Mm1) {
78
79           double [] Gim2 = G[i-2];
80
81           for (int j=1; j<Nm1; j=j+2){
82             if((j+1) != Nm1) {
83               Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
84                   + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
85             }
86           }
87
88         } else {
89
90           double [] Gip1 = G[i+1];
91           double [] Gim2 = G[i-2];
92
93           for (int j=1; j<Nm1; j=j+2){
94             Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
95                 + Gi[j+1]) + one_minus_omega * Gi[j];
96
97             if((j+1) != Nm1) {
98               Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
99                   + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
100             }
101           }
102         }
103
104       }
105
106       // Signal this thread has done iteration
107       sync[id][0]++;
108
109       // Wait for neighbours;
110       if (id > 0) {
111         while (sync[id-1][0] < sync[id][0]) ;
112       }
113       if (id < nthreads -1) {
114         while (sync[id+1][0] < sync[id][0]) ;
115       }
116     }
117
118   }
119 }