public class broadcasttest { public static int single sz = 10; public static final boolean DEBUG = false; public static void debug(String str) { if (DEBUG) { System.out.println("P" + Ti.thisProc() + "/" + Ti.numProcs() + ": " + str); System.out.flush(); } } public static void debug0(String str) { if (DEBUG && Ti.thisProc() == 0) { System.out.println(str); System.out.flush(); } } public static single void main (String [] args) { for (int single sender = 0; sender < Ti.numProcs(); sender++) { debug0("sender = " + sender); int [] xint = new int[sz]; long [] xlong = new long[sz]; float [] xfloat = new float[sz]; double [] xdouble = new double[sz]; MyObject [] xobj = new MyObject[sz]; MyImmut [] ximm = new MyImmut[sz]; // establish identical array contents on all processors for (int single i = 0; i < sz; i++) { debug0("i = " + i); debug0("broadcast int:"); xint[i] = broadcast (int)i from sender; debug0("broadcast long:"); xlong[i] = broadcast (long)i from sender; debug0("broadcast float:"); xfloat[i] = broadcast (float)i from sender; debug0("broadcast double:"); xdouble[i] = broadcast (double)i from sender; debug0("broadcast global Object reference:"); xobj[i] = broadcast (new MyObject(i)) from sender; debug0("broadcast large Immutable (bulk):"); ximm[i] = broadcast (new MyImmut(i)) from sender; } debug0("checking..."); // check them for (int j = 0; j < sz; j++) { if (xint[j] != (int)j) System.out.println(Ti.thisProc() + ": Error! Mismatched int value at j="+j); if (xlong[j] != (long)j) System.out.println(Ti.thisProc() + ": Error! Mismatched long value at j="+j); if (xfloat[j] != (float)j) System.out.println(Ti.thisProc() + ": Error! Mismatched float value at j="+j); if (xdouble[j] != (double)j) System.out.println(Ti.thisProc() + ": Error! Mismatched double value at j="+j); if (xobj[j].val != (int)j) System.out.println(Ti.thisProc() + ": Error! Mismatched object value at j="+j); if (ximm[j].val != (int)j) System.out.println(Ti.thisProc() + ": Error! Mismatched immutable value at j="+j); } } // for sender Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("done."); } } class MyObject { int val; public MyObject(int newval) { val = newval; } } immutable class MyImmut { long a; long b; long c; long d; long e; int val; long f; long g; long h; long i; long j; public MyImmut() {} public MyImmut(int newval) { val = newval; } }