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 *
16 * This version copyright (c) The University of Edinburgh, 2001. *
17 * All rights reserved. *
19 **************************************************************************/
21 import java.util.Random;
23 public class JGFSORBench {
32 public int cachelinesize;
35 public JGFInstrumentor instr;
37 public JGFSORBench(int nthreads, JGFInstrumentor instr){
38 this.nthreads = nthreads;
40 datasizes = new int[3];
44 JACOBI_NUM_ITER = 100;
45 RANDOM_SEED = 10101010;
46 R = new Random(RANDOM_SEED);
51 public void JGFsetsize(int size){
55 public static void JGFkernel(JGFSORBench sor, JGFInstrumentor instr) {
57 numthreads = sor.nthreads;
59 double G[][] = sor.RandomMatrix(sor.datasizes[sor.size], sor.datasizes[sor.size], sor.R);
63 int num_iterations = sor.JACOBI_NUM_ITER;
66 double omega_over_four = omega * 0.25;
67 double one_minus_omega = 1.0 - omega;
69 // update interior points
75 int cachelinesize = sor.cachelinesize;
77 SORRunner thobjects[] = new SORRunner[numthreads];
78 sor.sync = sor.init_sync(numthreads, cachelinesize);
80 JGFInstrumentor.startTimer("Section2:SOR:Kernel", instr.timers);
82 for(int i=1;i<numthreads;i++) {
83 thobjects[i] = new SORRunner(i,omega,G,num_iterations,sor.sync,numthreads);
87 thobjects[0] = new SORRunner(0,omega,G,num_iterations,sor.sync,numthreads);
92 catch (InterruptedException e) {}
95 for(int i=1;i<numthreads;i++) {
99 catch (InterruptedException e) {}
102 JGFInstrumentor.stopTimer("Section2:SOR:Kernel", instr.timers);
104 for (int i=1; i<Nm1; i++) {
105 for (int j=1; j<Nm1; j++) {
106 sor.Gtotal += G[i][j];
112 private long[][] init_sync(int nthreads, int cachelinesize) {
113 long sync[][] = new long [nthreads][cachelinesize];
114 for (int i = 0; i<nthreads; i++)
119 public void JGFvalidate(){
121 double refval[] = {0.498574406322512,1.1234778980135105,1.9954895063582696};
122 double dev = Math.abs(Gtotal - refval[size]);
124 System.out.println("Validation failed");
125 System.out.println("Gtotal = " + Gtotal + " " + dev + " " + size);
130 public void JGFtidyup(){
134 public void JGFrun(int size){
137 JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size);
146 JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (JACOBI_NUM_ITER));
148 JGFInstrumentor.printTimer("Section2:SOR:Kernel");
152 public double[][] RandomMatrix(int M, int N, Random R)
154 double A[][] = new double[M][N];
156 for (int i=0; i<N; i++)
157 for (int j=0; j<N; j++)
159 A[i][j] = R.nextDouble() * 1e-6;