1 /**************************************************************************
3 * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
7 * Java Grande Benchmarking Project *
11 * Edinburgh Parallel Computing Centre *
13 * email: epcc-javagrande@epcc.ed.ac.uk *
15 * adapted from SciMark 2.0, author Roldan Pozo (pozo@cam.nist.gov) *
17 * This version copyright (c) The University of Edinburgh, 2001. *
18 * All rights reserved. *
20 **************************************************************************/
22 class SORRunner extends Thread {
24 int id, num_iterations;
28 public SORRunner(int id, double omega, double G[][], int num_iterations, int nthreads) {
32 this.num_iterations=num_iterations;
33 this.nthreads = nthreads;
37 int tmpid, M, N, numthreads;
38 double omega_over_four, one_minus_omega;
41 barr = new Barrier("128.195.175.84");
42 int ilow, iupper, slice, tslice, ttslice, Mm1, Nm1;
47 omega_over_four = omega * 0.25;
48 one_minus_omega = 1.0 - omega;
49 numthreads = nthreads;
51 numiterations = num_iterations;
55 ttslice = (tslice + numthreads-1)/numthreads;
58 iupper = ((tmpid+1)*slice)+1;
59 if (iupper > Mm1) iupper = Mm1+1;
60 if (tmpid == (numthreads-1)) iupper = Mm1+1;
61 G[0]=global new double[N];
62 for(int i=ilow;i<iupper;i++) {
63 G[i]=global new double[N];
66 Barrier.enterBarrier(barr);
69 Random rand=new Random();
72 R[j]=rand.nextDouble() * 1e-6;
73 for(int i=ilow;i<iupper;i++) {
76 R[j]=rand.nextDouble() * 1e-6;
79 Barrier.enterBarrier(barr);
81 // update interior points
85 for (int p=0; p<2*numiterations; p++) {
87 for (int i=ilow+(p%2); i<iupper; i=i+2) {
90 double [] Gim1 = G[i-1];
93 double [] Gip1 = G[i+1];
95 for (int j=1; j<Nm1; j=j+2){
96 Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
97 + Gi[j+1]) + one_minus_omega * Gi[j];
100 } else if (i == Mm1) {
104 double [] Gip1 = G[i+1];
106 for (int j=1; j<Nm1; j=j+2){
107 Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
108 + Gi[j+1]) + one_minus_omega * Gi[j];
115 Barrier.enterBarrier(barr);
117 for (int i=ilow+(p%2); i<iupper; i=i+2) {
120 double [] Gim1 = G[i-1];
123 } else if (i == Mm1) {
125 double [] Gim2 = G[i-2];
127 for (int j=1; j<Nm1; j=j+2){
129 Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
130 + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
136 double [] Gim2 = G[i-2];
138 for (int j=1; j<Nm1; j=j+2){
140 Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
141 + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
148 Barrier.enterBarrier(barr);