import java.io.*; immutable class I { public int val; public String str1; public String str2; public I() {} public I(int val, String str1, String str2) { this.val = val; this.str1 = str1; this.str2 = str2; } } class exchangetest { public static void flush() { // extra time for GLUnix to flush streams try { Thread.sleep(2000); } catch (InterruptedException e) { } } public static single void orderedOutput(String s) { for (int single i=0; i < Ti.numProcs(); i++) { if (Ti.thisProc() == i) { System.out.println(s); flush(); } Ti.barrier(); } } single public static void main (String [] argv) { String id = ""; id = "P" + Ti.thisProc() + ": "; { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("long exchange"); long [1d] single allData; allData = new long [0:Ti.numProcs()-1]; allData.exchange(10 * Ti.thisProc()); String s = new String(); for (int i=0; i < Ti.numProcs(); i++) { s += allData[i] + " "; } orderedOutput(id+s); } { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("array exchange"); double [1d] single [1d] allArrays; allArrays = new double [0:Ti.numProcs()-1][1d]; double [1d][1d] junk = broadcast allArrays from 0; double [1d] single mydata = new double [0:9]; foreach (p in mydata.domain()) { mydata[p] = Ti.thisProc()*100 + p[1]; } allArrays.exchange(mydata); String s = new String(); for (int i=0; i < Ti.numProcs(); i++) { s += "| "; foreach (p in allArrays[i].domain()) { s += allArrays[i][p] + " "; } s += "|"; } orderedOutput(id+s); } { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("immutable exchange"); I [1d] single allData = new I [0:Ti.numProcs()-1]; allData.exchange(new I(100*Ti.thisProc(), new String(""+(100*Ti.thisProc()+1)), new String(""+(100*Ti.thisProc()+2)))); String s = new String(); for (int i=0; i < Ti.numProcs(); i++) { s += "|" + allData[i].val + " " + allData[i].str1 + " " + allData[i].str2 + "| "; } orderedOutput(id+s); } { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("exchange on remote array"); double [1d] single src; src = new double [0:Ti.numProcs()-1]; src = broadcast src from 1; src.exchange(Ti.thisProc() * 100.0); String s = new String(); for (int i=0; i < Ti.numProcs(); i++) { s += src[i] + " "; } orderedOutput(id+s); } { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("exchange on local array"); double [1d] local single lsrc; lsrc = new double [0:Ti.numProcs()-1]; lsrc.exchange(Ti.thisProc() * 100.0); String ls = new String(); for (int i=0; i < Ti.numProcs(); i++) { ls += lsrc[i] + " "; } orderedOutput(id+ls); } } }