+++ /dev/null
-public class JGFInstrumentor{
-
- private HashMap timers;
- private HashMap data;
-
- public JGFInstrumentor() {
- timers = new HashMap();
- data = new HashMap();
- }
- public static void addTimer (String name, String opname, int size){
-
- 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){
- 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){
- 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){
- if (timers.containsKey(name)) {
- ((JGFTimer) timers.get(name)).addops(count);
- }
- else {
- System.printString("JGFInstrumentor.addOpsToTimer: failed - timer " + name +
- " does not exist");
- }
- }
-
- public static void printTimer(String name){
- if (timers.containsKey(name)) {
- ((JGFTimer) timers.get(name)).print();
- }
- else {
- System.printString("JGFInstrumentor.printTimer: failed - timer " + name +
- " does not exist");
- }
- }
-
- public static void printHeader(int section, int size,int nthreads) {
-
- String header = new String("");
- String base = new String("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";
- }
- } else {
- System.printString("Error\n");
- }
-
- System.printString(header);
-
- if (nthreads == 1) {
- System.printString("Executing on " + nthreads + " thread");
- }
- else {
- System.printString("Executing on " + nthreads + " threads");
- }
-
- System.printString("");
-
- }
-
- /*
- public static void addTimeToTimer(String name, double added_time){
- 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){
- 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){
- if (timers.containsKey(name)) {
- ((JGFTimer) timers.get(name)).reset();
- }
- else {
- System.printString("JGFInstrumentor.resetTimer: failed - timer " + name +
- " does not exist");
- }
- }
-
-
- public static void printperfTimer(String name){
- 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){
- data.put(name,obj);
- }
-
- public static void retrieveData(String name, Object obj){
- obj = data.get(name);
- }
- public static void addTimer (String name){
-
- 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){
- if (timers.containsKey(name)) {
- System.printString("JGFInstrumentor.addTimer: warning - timer " + name +
- " already exists");
- }
- else {
- timers.put(name, new JGFTimer(name,opname));
- }
-
- }
- */
-}
+++ /dev/null
-public class JGFSORBench extends SOR{
-
- private int size;
- private int[] datasize;
- private final int JACOBI_NUM_ITER;
- private final long RANDOM_SEED;
- public int nthreads;
- Random R;
-
- public JGFSORBench() {
- JACOBI_NUM_ITER = 100;
- RANDOM_SEED = 10101010;
- R = new Random(RANDOM_SEED);
- }
-
- public JGFSORBench(int nthreads){
- this.nthreads = nthreads;
- int datasizes[] = new int[3];
- datasizes[0]= 1000;
- datasizes[1]= 1500;
- datasizes[2]= 2000;
- }
-
- public void JGFsetsize(int size){
- this.size = size;
- }
-
- public void JGFinitialise(){
-
- }
-
- public void JGFkernel(){
-
- double G[][] = RandomMatrix(datasizes[size], datasizes[size],R);
-
- SORrun(1.25, G, JACOBI_NUM_ITER, nthreads);
-
-
- }
-
- public void JGFvalidate(){
-
- double refval[] = new double[3];
- refval[0] = 0.498574406322512;
- refval[1] = 1.1234778980135105;
- refval[2] = 1.9954895063582696;
- double dev = Math.abs(Gtotal - refval[size]);
- if (dev > 1.0e-12 ){
- System.out.println("Validation failed");
- System.out.println("Gtotal = " + Gtotal + " " + dev + " " + size);
- }
- }
-
- public void JGFtidyup(){
- //System.gc();
- }
-
- public void JGFrun(int size){
-
-
- JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size);
-
- JGFsetsize(size);
- JGFinitialise();
- JGFkernel();
- JGFvalidate();
- JGFtidyup();
-
-
- JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (JACOBI_NUM_ITER));
-
- JGFInstrumentor.printTimer("Section2:SOR:Kernel");
- }
-
- private static double[][] RandomMatrix(int M, int N, java.util.Random R)
- {
- double A[][] = new double[M][N];
-
- for (int i=0; i<N; i++)
- for (int j=0; j<N; j++)
- {
- A[i][j] = R.nextDouble() * 1e-6;
- }
- return A;
- }
-
-
-}
+++ /dev/null
-public class JGFSORBenchSizeA{
- public int nthreads;
- public static void main(String argv[]){
-
- 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.printHeader(2,0,nthreads);
- JGFSORBench sor = null;
- atomic {
- sor = global new JGFSORBench(nthreads);
- sor.JGFrun(0);
- }
-
- }
-}
-
+++ /dev/null
-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.name = name;
- this.opname = opname;
- this.size = -1;
- 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,"");
- }
- */
-
- public void start(){
- if (on)
- System.printString("Warning timer " + name + " 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 " + name + " 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 " + (float)this.perf() + "\t"
- + " ("+opname+"/s)");
- } else if(size == 1) {
- System.printString(name + ":SizeB" + "\t" + time + " (s) \t " + (float)this.perf() + "\t"
- + " ("+opname+"/s)");
- } else if(size ==2) {
- System.printString(name + ":SizeC" + "\t" + time + " (s) \t " + (float)this.perf() + "\t"
- + " ("+opname+"/s)");
- } else {
- System.printString(name + "\t" + time + " (s) \t " + (float)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" + (float)this.perf() + "\t"
- + " ("+opname+"/s)");
- }
-
-}
+++ /dev/null
-public class SOR{
- public double Gtotal;
- public final int cachelinesize;
- public long[][] sync;
-
- public SOR() {
- Gtotal = 0.0;
- cachelinesize = 128;
- sync = null;
- }
-
- public static final void SORrun(double omega, double G[][], int num_iterations)
- {
- int M = G.length;
- int N = G[0].length;
-
- double omega_over_four = omega * 0.25;
- double one_minus_omega = 1.0 - omega;
-
-
- // update interior points
- //
- int Mm1 = M-1;
- int Nm1 = N-1;
-
- SORRunner thobjects[] = new SORRunner[JGFSORBench.nthreads];
- Thread th[] = new Thread[JGFSORBench.nthreads];
- sync = init_sync(JGFSORBench.nthreads);
-
- JGFInstrumentor.startTimer("Section2:SOR:Kernel");
-
- for(int i=1;i<JGFSORBench.nthreads;i++) {
- thobjects[i] = new SORRunner(i,omega,G,num_iterations,sync);
- th[i] = new Thread(thobjects[i]);
- th[i].start();
- }
-
- thobjects[0] = new SORRunner(0,omega,G,num_iterations,sync);
- thobjects[0].run();
-
-
- for(int i=1;i<JGFSORBench.nthreads;i++) {
- th[i].join();
- }
-
-
-
- JGFInstrumentor.stopTimer("Section2:SOR:Kernel");
-
- for (int i=1; i<Nm1; i++) {
- for (int j=1; j<Nm1; j++) {
- Gtotal += G[i][j];
- }
- }
-
- }
-
- private static long[][] init_sync(int nthreads) {
- long sync[][] = new long [JGFSORBench.nthreads][cachelinesize];
- for (int i = 0; i<JGFSORBench.nthreads; i++)
- sync[i][0] = 0;
- return sync;
- }
-
-}
-
-
-class SORRunner extends Thread {
-
- int id,num_iterations;
- double[][] G;
- double omega;
- long[][] sync;
-
- public SORRunner(int id, double omega, double G[][], int num_iterations,long[][] sync) {
- this.id = id;
- this.omega=omega;
- this.G=G;
- this.num_iterations=num_iterations;
- this.sync=sync;
- }
-
- public void run() {
-
- int M = G.length;
- int N = G[0].length;
-
- double omega_over_four = omega * 0.25;
- double one_minus_omega = 1.0 - omega;
-
- // update interior points
- //
- int Mm1 = M-1;
- int Nm1 = N-1;
-
-
- int ilow, iupper, slice, tslice, ttslice;
-
- tslice = (Mm1) / 2;
- ttslice = (tslice + JGFSORBench.nthreads-1)/JGFSORBench.nthreads;
- slice = ttslice*2;
-
- ilow=id*slice+1;
- iupper = ((id+1)*slice)+1;
- if (iupper > Mm1) iupper = Mm1+1;
- if (id == (JGFSORBench.nthreads-1)) iupper = Mm1+1;
-
- for (int p=0; p<2*num_iterations; p++) {
- for (int i=ilow+(p%2); i<iupper; i=i+2) {
-
-
- double [] Gi = G[i];
- double [] Gim1 = G[i-1];
-
-
- if(i == 1) {
- double [] Gip1 = G[i+1];
-
- 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) {
-
- double [] Gim2 = G[i-2];
-
- 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 [] Gip1 = G[i+1];
- double [] Gim2 = G[i-2];
-
- 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];
-
- 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];
- }
- }
- }
-
- }
-
- // Signal this thread has done iteration
- sync[id][0]++;
-
- // Wait for neighbours;
- if (id > 0) {
- while (sync[id-1][0] < sync[id][0]) ;
- }
- if (id < JGFSORBench.nthreads -1) {
- while (sync[id+1][0] < sync[id][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, 1999. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+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\n");
+ }
+ 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\n");
+ }
+ 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\n");
+ }
+ 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\n");
+ }
+
+ }
+
+ 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\n");
+ }
+ }
+
+ 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\n");
+ }
+ }
+
+ 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\n");
+ }
+
+
+
+ }
+
+ 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\n");
+ 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\n");
+ }
+ }
+
+ 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\n");
+ }
+ }
+
+ 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\n");
+ }
+ }
+
+ 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+"\n");
+
+ if (nthreads == 1) {
+ System.printString("Executing on " + nthreads + " thread\n");
+ }
+ else {
+ System.printString("Executing on " + nthreads + " threads\n");
+ }
+
+ System.printString("\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, 2001. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+public class JGFSORBench {
+
+ int size;
+ int[] datasizes;
+ int JACOBI_NUM_ITER;
+ long RANDOM_SEED;
+ public int nthreads;
+ Random R;
+ public double Gtotal;
+ public int cachelinesize;
+ public long sync[][];
+
+ public JGFSORBench(int nthreads){
+ this.nthreads = nthreads;
+ datasizes = global new int[3];
+ datasizes[0] = 1000;
+ datasizes[1] = 1500;
+ datasizes[2] = 2000;
+ JACOBI_NUM_ITER = 100;
+ RANDOM_SEED = 10101010;
+ R = global new Random(RANDOM_SEED);
+ Gtotal = 0.0;
+ cachelinesize = 128;
+ }
+
+ public void JGFsetsize(int size){
+ this.size = size;
+ }
+
+ public static void JGFkernel(JGFSORBench sor) {
+ int numthreads, datasize;
+ Random rand;
+ atomic {
+ numthreads = sor.nthreads;
+ rand = sor.R;
+ datasize = sor.datasizes[sor.size];
+ }
+
+ double[][] G;
+ int M, N;
+ atomic {
+ //G = global new double[datasize][datasize];
+ G = sor.RandomMatrix(datasize, datasize, rand);
+ M = G.length;
+ N = G[0].length;
+ }
+ double omega = 1.25;
+ int num_iterations;
+ atomic {
+ num_iterations = sor.JACOBI_NUM_ITER;
+ }
+
+ double omega_over_four = omega * 0.25;
+ double one_minus_omega = 1.0 - omega;
+
+ // update interior points
+ //
+ int Mm1 = M-1;
+ int Nm1 = N-1;
+
+ //spawn threads
+ int tmpcachelinesize;
+ atomic {
+ tmpcachelinesize = sor.cachelinesize;
+ }
+
+ SORRunner[] thobjects;
+ atomic {
+ thobjects = global new SORRunner[numthreads];
+ sor.sync = sor.init_sync(numthreads, tmpcachelinesize);
+ }
+
+ //JGFInstrumentor.startTimer("Section2:SOR:Kernel", instr.timers);
+
+ SORRunner tmp;
+ int mid = (128<<24)|(195<<16)|(175<<8)|73;
+ for(int i=1;i<numthreads;i++) {
+ atomic {
+ thobjects[i] = global new SORRunner(i,omega,G,num_iterations,sor.sync,numthreads);
+ tmp = thobjects[i];
+ }
+ tmp.start(mid);
+ }
+
+ atomic {
+ thobjects[0] = global new SORRunner(0,omega,G,num_iterations,sor.sync,numthreads);
+ tmp = thobjects[0];
+ }
+ tmp.start(mid);
+ tmp.join();
+
+ for(int i=1;i<numthreads;i++) {
+ atomic {
+ tmp = thobjects[i];
+ }
+ tmp.join();
+ }
+
+ //JGFInstrumentor.stopTimer("Section2:SOR:Kernel", instr.timers);
+
+ atomic {
+ for (int i=1; i<Nm1; i++) {
+ for (int j=1; j<Nm1; j++) {
+ sor.Gtotal += G[i][j];
+ }
+ }
+ }
+ }
+
+ public long[][] init_sync(int nthreads, int cachelinesize) {
+ long sync[][] = global new long [nthreads][cachelinesize];
+ for (int i = 0; i<nthreads; i++)
+ sync[i][0] = 0;
+ return sync;
+ }
+
+ public double[][] RandomMatrix(int M, int N, Random R)
+ {
+ double A[][] = global new double[M][N];
+
+ for (int i=0; i<N; i++)
+ for (int j=0; j<N; j++)
+ {
+ A[i][j] = R.nextDouble() * 1e-6;
+ }
+ return A;
+ }
+
+ public int JGFvalidate(){
+
+ double refval[];
+ refval = new double[3];
+ refval[0] = 0.498574406322512;
+ refval[1] = 1.1234778980135105;
+ refval[2] = 1.9954895063582696;
+ double dev = Math.fabs(Gtotal - refval[size]);
+ if (dev > 1.0e-12 ){
+ //System.printString("Validation failed");
+ //System.printString("Gtotal = " + (long) Gtotal * 1000000 + " " +(long) dev * 1000000 + " " + size);
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ /*
+ public void JGFtidyup(){
+ System.gc();
+ }
+
+ public void JGFrun(int size){
+
+
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size);
+
+ JGFsetsize(size);
+ JGFinitialise();
+ JGFkernel();
+ JGFvalidate();
+ JGFtidyup();
+
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (JACOBI_NUM_ITER));
+
+ JGFInstrumentor.printTimer("Section2:SOR:Kernel");
+ }
+ */
+
+
+}
--- /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;
+ atomic {
+ sor = global new JGFSORBench(nthreads);
+ }
+
+ int size = 0;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ atomic {
+ sor.JGFsetsize(size);
+ }
+ JGFSORBench.JGFkernel(sor);
+ System.printString("End of JGFkernel\n");
+ int retval;
+ atomic {
+ retval = sor.JGFvalidate();
+ }
+ if(retval!=0) {
+ System.printString("Validation failed");
+ }
+
+ int jacobi;
+ atomic {
+ jacobi = sor.JACOBI_NUM_ITER;
+ }
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) jacobi, 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;
+ atomic {
+ sor = global new JGFSORBench(nthreads);
+ }
+
+ int size = 1;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ atomic {
+ sor.JGFsetsize(size);
+ }
+ JGFSORBench.JGFkernel(sor);
+ System.printString("End of JGFkernel\n");
+ int retval;
+ atomic {
+ retval = sor.JGFvalidate();
+ }
+ if(retval!=0) {
+ System.printString("Validation failed");
+ }
+
+ int jacobi;
+ atomic {
+ jacobi = sor.JACOBI_NUM_ITER;
+ }
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) jacobi, 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.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,2,nthreads);
+
+ JGFSORBench sor;
+ atomic {
+ sor = global new JGFSORBench(nthreads);
+ }
+
+ int size = 2;
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size, instr.timers);
+
+ atomic {
+ sor.JGFsetsize(size);
+ }
+ JGFSORBench.JGFkernel(sor);
+ System.printString("End of JGFkernel\n");
+ int retval;
+ atomic {
+ retval = sor.JGFvalidate();
+ }
+ if(retval!=0) {
+ System.printString("Validation failed");
+ }
+
+ int jacobi;
+ atomic {
+ jacobi = sor.JACOBI_NUM_ITER;
+ }
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) jacobi, 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, 1999. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
+
+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\n");
+ 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\n");
+ 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)\n");
+ System.printString(name + " " + calls + " " + (long)time + " " + (long)this.perf() + "\n");
+ }
+
+ public void print(){
+ if (opname.equals("")) {
+ System.printString(name + " " + (long)time + " (s)\n");
+ }
+ else {
+ if(size == 0) {
+ System.printString(name + ":SizeA" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
+ } else if (size == 1) {
+ System.printString(name + ":SizeB" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
+ } else if (size == 2) {
+ System.printString(name + ":SizeC" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
+ } else{
+ System.printString(name + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
+ }
+ }
+ }
+
+
+ public void printperf(){
+
+ String name;
+ name = this.name;
+
+ // pad name to 40 characters
+ while ( name.length() < 40 ) name = name + " ";
+
+ System.printString(name + "\t" + (long)this.perf() + "\t"
+ + " ("+opname+"/s)\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 *
+ * *
+ * 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;
+ long sync[][];
+ int nthreads;
+
+ public SORRunner(int id, double omega, double G[][], int num_iterations,long[][] sync, int nthreads) {
+ this.id = id;
+ this.omega=omega;
+ this.G=G;
+ this.num_iterations=num_iterations;
+ this.sync=sync;
+ this.nthreads = nthreads;
+ }
+
+ public void run() {
+
+ int tmpid, M, N, numthreads;
+ double omega_over_four, one_minus_omega;
+ atomic {
+ M = G.length;
+ N = G[0].length;
+ omega_over_four = omega * 0.25;
+ one_minus_omega = 1.0 - omega;
+ numthreads = nthreads;
+ tmpid = id;
+ }
+
+ // update interior points
+ //
+ int Mm1 = M-1;
+ int Nm1 = N-1;
+
+
+ int ilow, iupper, slice, tslice, ttslice;
+
+ 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;
+
+ atomic {
+ for (int p=0; p<2*num_iterations; p++) {
+ for (int i=ilow+(p%2); i<iupper; i=i+2) {
+
+ double [] Gi = G[i];
+ double [] Gim1 = G[i-1];
+
+ if(i == 1) {
+ double [] Gip1 = G[i+1];
+
+ 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) {
+
+ double [] Gim2 = G[i-2];
+
+ 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 [] Gip1 = G[i+1];
+ double [] Gim2 = G[i-2];
+
+ 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];
+
+ 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];
+ }
+ }
+ }
+
+ }
+
+ // Signal this thread has done iteration
+ sync[id][0]++;
+
+ // Wait for neighbours;
+ if (id > 0) {
+ while (sync[id-1][0] < sync[id][0]) ;
+ }
+ if (id < nthreads -1) {
+ while (sync[id+1][0] < sync[id][0]) ;
+ }
+ }//end of outer for
+ }//end of atomic
+ }//end of run
+}
--- /dev/null
+MAINCLASS=JGFSORBenchSizeA
+SRC=${MAINCLASS}.java \
+JGFSORBench.java \
+JGFInstrumentor.java \
+JGFTimer.java \
+SORRunner.java
+FLAGS=-dsm -prefetch -nooptimize -debug -profile -excprefetch JGFSORBench.RandomMatrix -excprefetch JGFSORBench.init_sync -excprefetch JGFSORBench.JGFkernel -mainclass ${MAINCLASS} -o ${MAINCLASS} -trueprob 0.8
+FLAGS2=-dsm -nooptimize -debug -profile -mainclass ${MAINCLASS} -o ${MAINCLASS}NP
+
+default:
+ ../../../../buildscript ${FLAGS2} ${SRC}
+ ../../../../buildscript ${FLAGS} ${SRC}
+
+clean:
+ rm -rf tmpbuilddirectory
+ rm *.bin
--- /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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println("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.out.println(header);
+
+ if (nthreads == 1) {
+ System.out.println("Executing on " + nthreads + " thread");
+ }
+ else {
+ System.out.println("Executing on " + nthreads + " threads");
+ }
+
+ System.out.println("");
+ }
+}
--- /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. *
+ * *
+ **************************************************************************/
+
+import java.util.Random;
+
+public class JGFSORBench {
+
+ int size;
+ int[] datasizes;
+ int JACOBI_NUM_ITER;
+ long RANDOM_SEED;
+ public int nthreads;
+ Random R;
+ public double Gtotal;
+ public int cachelinesize;
+ public long sync[][];
+
+ public JGFInstrumentor instr;
+
+ public JGFSORBench(int nthreads, JGFInstrumentor instr){
+ this.nthreads = nthreads;
+ this.instr = instr;
+ datasizes = new int[3];
+ datasizes[0] = 1000;
+ datasizes[1] = 1500;
+ datasizes[2] = 2000;
+ JACOBI_NUM_ITER = 100;
+ RANDOM_SEED = 10101010;
+ R = new Random(RANDOM_SEED);
+ Gtotal = 0.0;
+ cachelinesize = 128;
+ }
+
+ public void JGFsetsize(int size){
+ this.size = size;
+ }
+
+ public static void JGFkernel(JGFSORBench sor, JGFInstrumentor instr) {
+ int numthreads;
+ numthreads = sor.nthreads;
+
+ double G[][] = sor.RandomMatrix(sor.datasizes[sor.size], sor.datasizes[sor.size], sor.R);
+ int M = G.length;
+ int N = G[0].length;
+ double omega = 1.25;
+ int num_iterations = sor.JACOBI_NUM_ITER;
+
+
+ double omega_over_four = omega * 0.25;
+ double one_minus_omega = 1.0 - omega;
+
+ // update interior points
+ //
+ int Mm1 = M-1;
+ int Nm1 = N-1;
+
+ //spawn threads
+ int cachelinesize = sor.cachelinesize;
+
+ SORRunner thobjects[] = new SORRunner[numthreads];
+ sor.sync = sor.init_sync(numthreads, cachelinesize);
+
+ JGFInstrumentor.startTimer("Section2:SOR:Kernel", instr.timers);
+
+ for(int i=1;i<numthreads;i++) {
+ thobjects[i] = new SORRunner(i,omega,G,num_iterations,sor.sync,numthreads);
+ thobjects[i].start();
+ }
+
+ thobjects[0] = new SORRunner(0,omega,G,num_iterations,sor.sync,numthreads);
+ thobjects[0].start();
+ try {
+ thobjects[0].join();
+ }
+ catch (InterruptedException e) {}
+
+
+ for(int i=1;i<numthreads;i++) {
+ try {
+ thobjects[i].join();
+ }
+ catch (InterruptedException e) {}
+ }
+
+ JGFInstrumentor.stopTimer("Section2:SOR:Kernel", instr.timers);
+
+ for (int i=1; i<Nm1; i++) {
+ for (int j=1; j<Nm1; j++) {
+ sor.Gtotal += G[i][j];
+ }
+ }
+
+ }
+
+ private long[][] init_sync(int nthreads, int cachelinesize) {
+ long sync[][] = new long [nthreads][cachelinesize];
+ for (int i = 0; i<nthreads; i++)
+ sync[i][0] = 0;
+ return sync;
+ }
+
+ public void JGFvalidate(){
+
+ double refval[] = {0.498574406322512,1.1234778980135105,1.9954895063582696};
+ double dev = Math.abs(Gtotal - refval[size]);
+ if (dev > 1.0e-12 ){
+ System.out.println("Validation failed");
+ System.out.println("Gtotal = " + Gtotal + " " + dev + " " + size);
+ }
+ }
+
+ /*
+ public void JGFtidyup(){
+ System.gc();
+ }
+
+ public void JGFrun(int size){
+
+
+ JGFInstrumentor.addTimer("Section2:SOR:Kernel", "Iterations",size);
+
+ JGFsetsize(size);
+ JGFinitialise();
+ JGFkernel();
+ JGFvalidate();
+ JGFtidyup();
+
+
+ JGFInstrumentor.addOpsToTimer("Section2:SOR:Kernel", (double) (JACOBI_NUM_ITER));
+
+ JGFInstrumentor.printTimer("Section2:SOR:Kernel");
+ }
+ */
+
+ public double[][] RandomMatrix(int M, int N, Random R)
+ {
+ double A[][] = new double[M][N];
+
+ for (int i=0; i<N; i++)
+ for (int j=0; j<N; j++)
+ {
+ A[i][j] = R.nextDouble() * 1e-6;
+ }
+ return A;
+ }
+
+
+}
--- /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.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,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.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,2,nthreads);
+
+ JGFSORBench sor = new JGFSORBench(nthreads,instr);
+
+ int size = 2;
+ 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, 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.out.println("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.out.println("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.out.println("Timer Calls Time(s) Performance("+opname+"/s)");
+ System.out.println(name + " " + calls + " " + time + " " + this.perf());
+ }
+
+ public void print(){
+ if (opname.equals("")) {
+ System.out.println(name + " " + time + " (s)");
+ }
+ else {
+ if(size == 0) {
+ System.out.println(name + ":SizeA" + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ } else if (size == 1) {
+ System.out.println(name + ":SizeB" + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ } else if (size == 2) {
+ System.out.println(name + ":SizeC" + "\t" + time + " (s) \t " + this.perf() + "\t" + " ("+opname+"/s)");
+ } else{
+ System.out.println(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.out.println(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;
+ long sync[][];
+ int nthreads;
+
+ public SORRunner(int id, double omega, double G[][], int num_iterations,long[][] sync, int nthreads) {
+ this.id = id;
+ this.omega=omega;
+ this.G=G;
+ this.num_iterations=num_iterations;
+ this.sync=sync;
+ this.nthreads = nthreads;
+ }
+
+ public void run() {
+
+ int M = G.length;
+ int N = G[0].length;
+
+ double omega_over_four = omega * 0.25;
+ double one_minus_omega = 1.0 - omega;
+
+ // update interior points
+ //
+ int Mm1 = M-1;
+ int Nm1 = N-1;
+
+
+ int ilow, iupper, slice, tslice, ttslice;
+
+ tslice = (Mm1) / 2;
+ ttslice = (tslice + nthreads-1)/nthreads;
+ slice = ttslice*2;
+
+ ilow=id*slice+1;
+ iupper = ((id+1)*slice)+1;
+ if (iupper > Mm1) iupper = Mm1+1;
+ if (id == (nthreads-1)) iupper = Mm1+1;
+
+ for (int p=0; p<2*num_iterations; p++) {
+ for (int i=ilow+(p%2); i<iupper; i=i+2) {
+
+ double [] Gi = G[i];
+ double [] Gim1 = G[i-1];
+
+ if(i == 1) {
+ double [] Gip1 = G[i+1];
+
+ 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) {
+
+ double [] Gim2 = G[i-2];
+
+ 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 [] Gip1 = G[i+1];
+ double [] Gim2 = G[i-2];
+
+ 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];
+
+ 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];
+ }
+ }
+ }
+
+ }
+
+ // Signal this thread has done iteration
+ sync[id][0]++;
+
+ // Wait for neighbours;
+ if (id > 0) {
+ while (sync[id-1][0] < sync[id][0]) ;
+ }
+ if (id < nthreads -1) {
+ while (sync[id+1][0] < sync[id][0]) ;
+ }
+ }
+
+ }
+}
--- /dev/null
+SRC = JGFSORBenchSizeA
+default:
+ javac ${SRC}.java
+run:
+ java ${SRC} 2
+
+clean:
+ rm *.class
+++ /dev/null
-MAINCLASS=JGFSORBenchSizeA
-SRC=${MAINCLASS}.java JGFInstrumentor.java JGFTimer.java JGFSORBench.java SOR.java Random.java
-FLAGS=-dsm -prefetch -nooptimize -debug -mainclass ${MAINCLASS} -o ${MAINCLASS}
-default:
- ../../../buildscript ${FLAGS} ${SRC}