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 for(int i=1;i<numthreads;i++) {
96 JGFInstrumentor.stopTimer("Section2:SOR:Kernel", instr.timers);
98 for (int i=1; i<Nm1; i++) {
99 for (int j=1; j<Nm1; j++) {
100 sor.Gtotal += G[i][j];
106 private long[][] init_sync(int nthreads, int cachelinesize) {
107 long sync[][] = new long [nthreads][cachelinesize];
108 for (int i = 0; i<nthreads; i++)
113 public void JGFvalidate(){
115 double refval[]=new double[3];
116 refval[0]=0.498574406322512;
117 refval[1]=1.1234778980135105;
118 refval[2]=1.9954895063582696;
119 double dev = Math.abs(Gtotal - refval[size]);
121 System.printString("Validation failed");
122 System.printString("Gtotal = " + Gtotal + " " + dev + " " + size);
127 public void JGFtidyup(){
131 public void JGFrun(int size){
134 JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size);
143 JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (JACOBI_NUM_ITER));
145 JGFInstrumentor.printTimer("Section2:SOR:Kernel");
149 public double[][] RandomMatrix(int M, int N, Random R)
151 double A[][] = new double[M][N];
153 for (int i=0; i<N; i++)
154 for (int j=0; j<N; j++)
156 A[i][j] = R.nextDouble() * 1e-6;