import java.lang.Double; public class STREAM { static Object lock = new Object(); static Object lock2 = new Object(); static volatile int _barrier; static void reach_barrier() { synchronized(lock2) { _barrier++; } } static double total_bandwidth[] = new double[4]; static String[] label = { "Copy: ", "Scale: ", "Add: ", "Triad: " }; int N; int M; int NTIMES; int OFFSET; String HLINE ; int precision; double[] a ; double[] b; double[] c; double[] avgtime; double[] maxtime; double[] mintime; double[] bytes; Double tmp; double FLT_MAX; long pr(long ticks, int pid, String msg) { long t = System.currentTimeMillis(); System.out.println("PID "+pid+msg+" ("+((t-ticks)/1000)+" secs since last report)"); return t; } public void run(int pid) { long ticks = pr(System.currentTimeMillis(),pid," begins to allocate"); N = 200000; M = 20; NTIMES=10; OFFSET=0; HLINE= "-------------------------------------------------------------"; precision = 8; // java uses 8bytes per DOUBLE PRECISION word tmp= new Double(0); FLT_MAX =tmp.longBitsToDouble(0x7fefffffffffffffL); a = new double[N+OFFSET]; b = new double[N+OFFSET]; c = new double[N+OFFSET]; avgtime = new double[4]; maxtime = new double[4]; mintime = new double[4]; mintime[0] = FLT_MAX; mintime[1] = FLT_MAX; mintime[2] = FLT_MAX; mintime[3] = FLT_MAX; bytes= new double[4]; bytes[0] = 2 * precision * N; bytes[1] = 2 * precision * N; bytes[2] = 3 * precision * N; bytes[3] = 3 * precision * N; int BytesPerWord; int j, k; double scalar; double[][] times = new double[4][NTIMES]; /* --- SETUP --- determine precision and check timing --- */ BytesPerWord = precision; //System.out.println(HLINE); //System.out.println("This system uses " + BytesPerWord+" bytes per DOUBLE PRECISION word." ); //System.out.println("Array size = "+ N+", Offset = "+OFFSET); //System.out.println("Total memory required = "+ ((3.0 * BytesPerWord) * ( (double) N / 1048576.0)) + " MB." ); //System.out.println("Each test is run "+NTIMES+" times, but only the *best* time for each is used."); /* Get initial value for system clock. */ for (j=0; jy) return x; else return y; } public static void main(String args[]) { int num_threads = Integer.parseInt(args[0]); System.out.println("=== Warmup 0"); new STREAM().run(0); System.out.println("=== Warmup 1"); new STREAM().run(1); System.out.println("=== Warmup 2"); new STREAM().run(2); System.out.println("=== Warmup 3"); new STREAM().run(3); _barrier = 0; // Reset barrier for( int i=0; i<4; i++ ) total_bandwidth[i] = 0.0; Thread ts[] = new Thread[num_threads]; synchronized(lock) { for( int i=0; i