--- /dev/null
+/**************************************************************************
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * *
+ * This version copyright (c) The University of Edinburgh, 1999. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+import java.util.*;
+public class JGFInstrumentor{
+
+ protected HashMap timers;
+ protected HashMap data;
+
+ public JGFInstrumentor() {
+ timers = new HashMap();
+ data = new HashMap();
+ }
+
+ public static void addTimer (String name, HashMap timers){
+
+ if (timers.containsKey(name)) {
+ System.printString("JGFInstrumentor.addTimer: warning - timer " + name +
+ " already exists");
+ }
+ else {
+ timers.put(name, new JGFTimer(name));
+ }
+ }
+
+ public static void addTimer (String name, String opname, HashMap timers){
+
+ if (timers.containsKey(name)) {
+ System.printString("JGFInstrumentor.addTimer: warning - timer " + name +
+ " already exists");
+ }
+ else {
+ timers.put(name, new JGFTimer(name,opname));
+ }
+
+ }
+
+ public static void addTimer (String name, String opname, int size, HashMap timers){
+
+ if (timers.containsKey(name)) {
+ System.printString("JGFInstrumentor.addTimer: warning - timer " + name +
+ " already exists");
+ }
+ else {
+ timers.put(name, new JGFTimer(name,opname,size));
+ }
+
+ }
+
+ public static void startTimer(String name, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).start();
+ }
+ else {
+ System.printString("JGFInstrumentor.startTimer: failed - timer " + name +
+ " does not exist");
+ }
+
+ }
+
+ public static void stopTimer(String name, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).stop();
+ }
+ else {
+ System.printString("JGFInstrumentor.stopTimer: failed - timer " + name +
+ " does not exist");
+ }
+ }
+
+ public static void addOpsToTimer(String name, double count, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).addops(count);
+ }
+ else {
+ System.printString("JGFInstrumentor.addOpsToTimer: failed - timer " + name +
+ " does not exist");
+ }
+ }
+
+ public static void addTimeToTimer(String name, double added_time, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).addtime(added_time);
+ }
+ else {
+ System.printString("JGFInstrumentor.addTimeToTimer: failed - timer " + name +
+ " does not exist");
+ }
+
+
+
+ }
+
+ public static double readTimer(String name, HashMap timers){
+ double time;
+ if (timers.containsKey(name)) {
+ time = ((JGFTimer) timers.get(name)).time;
+ }
+ else {
+ System.printString("JGFInstrumentor.readTimer: failed - timer " + name +
+ " does not exist");
+ time = 0.0;
+ }
+ return time;
+ }
+
+ public static void resetTimer(String name, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).reset();
+ }
+ else {
+ System.printString("JGFInstrumentor.resetTimer: failed - timer " + name +
+ " does not exist");
+ }
+ }
+
+ public static void printTimer(String name, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).print();
+ }
+ else {
+ System.printString("JGFInstrumentor.printTimer: failed - timer " + name +
+ " does not exist");
+ }
+ }
+
+ public static void printperfTimer(String name, HashMap timers){
+ if (timers.containsKey(name)) {
+ ((JGFTimer) timers.get(name)).printperf();
+ }
+ else {
+ System.printString("JGFInstrumentor.printTimer: failed - timer " + name +
+ " does not exist");
+ }
+ }
+
+ public static void storeData(String name, Object obj, HashMap data){
+ data.put(name,obj);
+ }
+
+ public static void retrieveData(String name, Object obj, HashMap data){
+ obj = data.get(name);
+ }
+
+ public static void printHeader(int section, int size,int nthreads) {
+
+ String header, base;
+
+ header = "";
+ base = "Java Grande Forum Thread Benchmark Suite - Version 1.0 - Section ";
+
+ if (section == 1)
+ {
+ header = base + "1";
+ }
+ else if (section == 2)
+ {
+ if (size == 0)
+ header = base + "2 - Size A";
+ else if (size == 1)
+ header = base + "2 - Size B";
+ else if (size == 2)
+ header = base + "2 - Size C";
+ }
+ else if (section == 3)
+ {
+ if (size == 0)
+ header = base + "3 - Size A";
+ else if (size == 1)
+ header = base + "3 - Size B";
+ }
+
+ System.printString(header);
+
+ if (nthreads == 1) {
+ System.printString("Executing on " + nthreads + " thread");
+ }
+ else {
+ System.printString("Executing on " + nthreads + " threads");
+ }
+
+ System.printString("");
+ }
+}
--- /dev/null
+/**************************************************************************
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * *
+ * This version copyright (c) The University of Edinburgh, 2001. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+public class JGFSORBench {
+
+ int size;
+ int[] datasizes;
+ int JACOBI_NUM_ITER;
+ long RANDOM_SEED;
+ public int nthreads;
+ public double Gtotal;
+
+ public JGFSORBench(int nthreads){
+ this.nthreads = nthreads;
+ datasizes = new int[4];
+ datasizes[0] = 1000;
+ datasizes[1] = 1500;
+ datasizes[2] = 2000;
+ datasizes[3] = 8000;
+ JACOBI_NUM_ITER = 100;
+ RANDOM_SEED = 10101010;
+ Gtotal = 0.0;
+ }
+
+ public void JGFsetsize(int size){
+ this.size = size;
+ }
+
+ public static void JGFkernel(JGFSORBench sor) {
+ int numthreads, datasize;
+ double[][] G;
+ int num_iterations;
+ long RANDOM_SEED;
+
+ numthreads = sor.nthreads;
+ datasize = sor.datasizes[sor.size];
+ G = new double[datasize][];
+ num_iterations = sor.JACOBI_NUM_ITER;
+ RANDOM_SEED = sor.RANDOM_SEED;
+
+ double omega = 1.25;
+ double omega_over_four = omega * 0.25;
+ double one_minus_omega = 1.0 - omega;
+
+ // update interior points
+ //
+ //spawn threads
+
+ SORWrap[] thobjects = new SORWrap[numthreads];
+
+ for(int i=0;i<numthreads;i++) {
+ thobjects[i] = new SORWrap(new SORRunner(i,omega,G,num_iterations,numthreads, RANDOM_SEED));
+ }
+
+ for(int i=0;i<numthreads;i++) {
+ thobjects[i].sor.run();
+ }
+
+ //JGFInstrumentor.stopTimer("Section2:SOR:Kernel", instr.timers);
+ for (int i=1; i<G.length-1; i++) {
+ for (int j=1; j<G.length-1; j++) {
+ sor.Gtotal += G[i][j];
+ }
+ }
+ //System.out.println("DEBUG: G.length= " + G.length+" sor.Gtotal= " + sor.Gtotal);
+ }
+
+ public int JGFvalidate(){
+
+ double refval[];
+ refval = new double[4];
+ refval[0] = 0.498574406322512;
+ refval[1] = 1.1234778980135105;
+ refval[2] = 1.9954895063582696;
+ refval[3] = 2.654895063582696;
+ double dev = Math.fabs(Gtotal - refval[size]);
+ long l = (long) refval[size] * 1000000;
+ long r = (long) Gtotal * 1000000;
+ if (l != r ){
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+}
--- /dev/null
+/**************************************************************************
+* *
+* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+* *
+* produced by *
+* *
+* Java Grande Benchmarking Project *
+* *
+* at *
+* *
+* Edinburgh Parallel Computing Centre *
+* *
+* email: epcc-javagrande@epcc.ed.ac.uk *
+* *
+* *
+* This version copyright (c) The University of Edinburgh, 2001. *
+* All rights reserved. *
+* *
+**************************************************************************/
+
+
+public class JGFSORBenchSizeA{
+
+ public static void main(String argv[]){
+
+ int nthreads;
+
+ if(argv.length != 0 ) {
+ nthreads = Integer.parseInt(argv[0]);
+ } else {
+ System.printString("The no of threads has not been specified, defaulting to 1");
+ System.printString(" ");
+ nthreads = 1;
+ }
+
+ JGFInstrumentor instr = new JGFInstrumentor();
+ JGFInstrumentor.printHeader(2,0,nthreads);
+
+ JGFSORBench sor = new JGFSORBench(nthreads,instr);
+
+ int size = 0;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ sor.JGFsetsize(size);
+ JGFSORBench.JGFkernel(sor,instr);
+ sor.JGFvalidate();
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (sor.JACOBI_NUM_ITER), instr.timers);
+
+ JGFInstrumentor.printTimer("Section2:SOR:Kernel", instr.timers);
+
+ }
+}
+
--- /dev/null
+/**************************************************************************
+* *
+* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+* *
+* produced by *
+* *
+* Java Grande Benchmarking Project *
+* *
+* at *
+* *
+* Edinburgh Parallel Computing Centre *
+* *
+* email: epcc-javagrande@epcc.ed.ac.uk *
+* *
+* *
+* This version copyright (c) The University of Edinburgh, 2001. *
+* All rights reserved. *
+* *
+**************************************************************************/
+
+public class JGFSORBenchSizeB{
+
+ public static void main(String argv[]){
+ int nthreads;
+
+ if(argv.length != 0 ) {
+ nthreads = Integer.parseInt(argv[0]);
+ } else {
+ System.out.println("The no of threads has not been specified, defaulting to 1");
+ System.out.println(" ");
+ nthreads = 1;
+ }
+
+ JGFInstrumentor instr = new JGFInstrumentor();
+ JGFInstrumentor.printHeader(2,1,nthreads);
+
+ JGFSORBench sor = new JGFSORBench(nthreads,instr);
+ int size = 1;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ sor.JGFsetsize(size);
+ sor.JGFkernel();
+ sor.JGFvalidate();
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (sor.JACOBI_NUM_ITER), instr.timers);
+
+ JGFInstrumentor.printTimer("Section2:SOR:Kernel", instr.timers);
+
+ }
+}
+
+
--- /dev/null
+/**************************************************************************
+* *
+* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+* *
+* produced by *
+* *
+* Java Grande Benchmarking Project *
+* *
+* at *
+* *
+* Edinburgh Parallel Computing Centre *
+* *
+* email: epcc-javagrande@epcc.ed.ac.uk *
+* *
+* *
+* This version copyright (c) The University of Edinburgh, 2001. *
+* All rights reserved. *
+* *
+**************************************************************************/
+
+public class JGFSORBenchSizeC{
+
+ public static void main(String argv[]){
+
+ int nthreads;
+ if(argv.length != 0 ) {
+ nthreads = Integer.parseInt(argv[0]);
+ } else {
+ System.printString("The no of threads has not been specified, defaulting to 1");
+ System.printString(" ");
+ nthreads = 1;
+ }
+
+ JGFInstrumentor instr = new JGFInstrumentor();
+ JGFInstrumentor.printHeader(2,2,nthreads);
+
+ JGFSORBench sor = new JGFSORBench(nthreads,instr);
+
+ int size = 2;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ sor.JGFsetsize(size);
+ JGFSORBench.JGFkernel(sor,instr);
+ sor.JGFvalidate();
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (sor.JACOBI_NUM_ITER), instr.timers);
+
+ JGFInstrumentor.printTimer("Section2:SOR:Kernel", instr.timers);
+
+ }
+}
+
+
--- /dev/null
+/**************************************************************************
+* *
+* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+* *
+* produced by *
+* *
+* Java Grande Benchmarking Project *
+* *
+* at *
+* *
+* Edinburgh Parallel Computing Centre *
+* *
+* email: epcc-javagrande@epcc.ed.ac.uk *
+* *
+* *
+* This version copyright (c) The University of Edinburgh, 2001. *
+* All rights reserved. *
+* *
+**************************************************************************/
+
+public class JGFSORBenchSizeD{
+
+ public static void main(String argv[]){
+
+ int nthreads;
+ if(argv.length != 0 ) {
+ nthreads = Integer.parseInt(argv[0]);
+ } else {
+ System.printString("The no of threads has not been specified, defaulting to 1\n");
+ System.printString(" \n");
+ nthreads = 1;
+ }
+
+ JGFInstrumentor instr = new JGFInstrumentor();
+ //JGFInstrumentor.printHeader(2,0,nthreads);
+
+ JGFSORBench sor;
+ sor = new JGFSORBench(nthreads);
+
+ int size = 3;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ sor.JGFsetsize(size);
+ JGFSORBench.JGFkernel(sor);
+ int retval = 0;
+ /*
+ retval = sor.JGFvalidate();
+ */
+ if(retval!=0) {
+ System.printString("Validation failed\n");
+ }
+
+ int jacobi;
+ jacobi = sor.JACOBI_NUM_ITER;
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (sor.JACOBI_NUM_ITER), instr.timers);
+
+ JGFInstrumentor.printTimer("Section2:SOR:Kernel", instr.timers);
+
+ System.printString("Finished\n");
+ }
+}
--- /dev/null
+/**************************************************************************
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * *
+ * This version copyright (c) The University of Edinburgh, 1999. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+import java.util.*;
+
+public class JGFTimer {
+
+ public String name;
+ public String opname;
+ public double time;
+ public double opcount;
+ public long calls;
+ public int size;
+
+ private long start_time;
+ private boolean on;
+
+ public JGFTimer(String name, String opname){
+ this.size = -1;
+ this.name = name;
+ this.opname = opname;
+ reset();
+ }
+
+ public JGFTimer(String name, String opname, int size){
+ this.name = name;
+ this.opname = opname;
+ this.size = size;
+ reset();
+ }
+
+ public JGFTimer(String name){
+ this.name = name;
+ this.opname = "";
+ reset();
+ }
+
+
+
+ public void start(){
+ if (on) System.printString("Warning timer " + " was already turned on");
+ on = true;
+ start_time = System.currentTimeMillis();
+ }
+
+
+ public void stop(){
+ time += (double) (System.currentTimeMillis()-start_time) / 1000.;
+ if (!on) System.printString("Warning timer " + " wasn't turned on");
+ calls++;
+ on = false;
+ }
+
+ public void addops(double count){
+ opcount += count;
+ }
+
+ public void addtime(double added_time){
+ time += added_time;
+ }
+
+ public void reset(){
+ time = 0.0;
+ calls = 0;
+ opcount = 0;
+ on = false;
+ }
+
+ public double perf(){
+ return opcount / time;
+ }
+
+ public void longprint(){
+ System.printString("Timer Calls Time(s) Performance("+opname+"/s)");
+ System.printString(name + " " + calls + " " + time + " " + this.perf());
+ }
+
+ public void print(){
+ if (opname.equals("")) {
+ System.printString(name + " " + time + " (s)");
+ }
+ else {
+ if(size == 0) {
+ System.printString(name + ":SizeA" + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ } else if (size == 1) {
+ System.printString(name + ":SizeB" + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ } else if (size == 2) {
+ System.printString(name + ":SizeC" + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ } else{
+ System.printString(name + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ }
+ }
+ }
+
+
+ public void printperf(){
+
+ String name;
+ name = this.name;
+
+ // pad name to 40 characters
+ while ( name.length() < 40 ) name = name + " ";
+
+ System.printString(name + "\t" + this.perf() + "\t"
+ + " ("+opname+"/s)");
+ }
+
+}
--- /dev/null
+/**************************************************************************
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * adapted from SciMark 2.0, author Roldan Pozo (pozo@cam.nist.gov) *
+ * *
+ * This version copyright (c) The University of Edinburgh, 2001. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+
+class SORRunner extends Thread {
+
+ int id, num_iterations;
+ double G[][],omega;
+ int nthreads;
+ long RANDOM_SEED;
+
+ public SORRunner(int id, double omega, double G[][], int num_iterations, int nthreads, long RANDOM_SEED) {
+ this.id = id;
+ this.omega=omega;
+ this.G=G;
+ this.num_iterations=num_iterations;
+ this.nthreads = nthreads;
+ this.RANDOM_SEED = RANDOM_SEED;
+ }
+
+ public void run() {
+ int tmpid, M, N, numthreads;
+ double omega_over_four, one_minus_omega;
+ int numiterations;
+ int ilow, iupper, slice, tslice, ttslice, Mm1, Nm1;
+
+ N = M = G.length;
+
+ omega_over_four = omega * 0.25;
+ one_minus_omega = 1.0 - omega;
+ numthreads = nthreads;
+ tmpid = id;
+ numiterations = num_iterations;
+ Mm1 = M-1;
+ Nm1 = N-1;
+ tslice = (Mm1) / 2;
+ ttslice = (tslice + numthreads-1)/numthreads;
+ slice = ttslice*2;
+ ilow=tmpid*slice+1;
+ iupper = ((tmpid+1)*slice)+1;
+ if (iupper > Mm1) iupper = Mm1+1;
+ if (tmpid == (numthreads-1)) iupper = Mm1+1;
+ G[0]=new double[N];
+ for(int i=ilow;i<iupper;i++) {
+ G[i]=new double[N];
+ }
+
+ //barrier
+
+ Random rand=new Random(RANDOM_SEED);
+ double[] R = G[0];
+ for(int j=0;j<M;j++)
+ R[j]=rand.nextDouble() * 1e-6;
+ for(int i=ilow;i<iupper;i++) {
+ R=G[i];
+ for(int j=0;j<M;j++)
+ R[j]=rand.nextDouble() * 1e-6;
+ }
+
+ // update interior points
+ //
+
+ //barrier
+
+ for (int p=0; p<2*numiterations; p++) {
+ for (int q=0;q<=2;q+=2) {//new line
+
+ for (int i=ilow+(p%2)+q; i<iupper; i=i+4) {//changed 2->4 and added q
+
+ double [] Gi = G[i];
+ double [] Gim1 = G[i-1];
+
+ if(i == 1) {
+ double [] Gip1 = G[i+1];
+
+ sese first {
+ for (int j=1; j<Nm1; j=j+2){
+ Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
+ + Gi[j+1]) + one_minus_omega * Gi[j];
+
+ }
+ }
+ } else if (i == Mm1) {
+
+ } else {
+
+ double [] Gip1 = G[i+1];
+ sese second {
+ for (int j=1; j<Nm1; j=j+2){
+ Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
+ + Gi[j+1]) + one_minus_omega * Gi[j];
+
+ }
+ }
+ }
+ }
+ } //new line
+
+ //barrier
+ for (int q=0;q<=2;q+=2) {//new line
+ for (int i=ilow+(p%2)+q; i<iupper; i=i+4) { //added q, changed 2->4
+
+ double [] Gi = G[i];
+ double [] Gim1 = G[i-1];
+
+ if(i == 1) {
+ } else if (i == Mm1) {
+
+ double [] Gim2 = G[i-2];
+
+ sese three {
+ for (int j=1; j<Nm1; j=j+2){
+ if((j+1) != Nm1) {
+ Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
+ + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
+ }
+ }
+ }
+
+ } else {
+
+ double [] Gim2 = G[i-2];
+
+ sese four {
+ for (int j=1; j<Nm1; j=j+2){
+ if((j+1) != Nm1) {
+ Gim1[j+1]=omega_over_four * (Gim2[j+1] + Gi[j+1] + Gim1[j]
+ + Gim1[j+2]) + one_minus_omega * Gim1[j+1];
+ }
+ }
+ }
+ }
+ }
+ }
+ //barrier
+ }//end of for
+ } //end of run()
+}
--- /dev/null
+public class SORWrap {
+ public SORRunner sor;
+ public SORWrap() {
+ }
+
+ public SORWrap(SORRunner e) {
+ sor=e;
+ }
+}