import ti.io.*; import java.io.*; import java.lang.*; public class taglobtest { public static long starttime; public static void MSG(String s) { System.out.println((System.currentTimeMillis() - starttime) / 1000.0 + "(" + Ti.thisProc() + "/" + Ti.numProcs() + "): " + s); } public static single void main (String single [] single args) { starttime = System.currentTimeMillis(); if (args.length != 1) { MSG("Usage: taglobtest "); //throw new InternalError("bad thing"); } String infilename = args[0]; String outfilename = "taglobtest.tmp." + Ti.thisProc(); File infile = new File(infilename); File outfile = new File(outfilename); try { MSG("File size is: " + infile.length()); int len = (int)infile.length(); { if (Ti.thisProc() == 0) MSG(" -------------- Beginning global contig array test.. -------------- "); BulkRandomAccessFile mybrafin; BulkRandomAccessFile mybrafout; try { if (outfile.exists()) outfile.delete(); mybrafin = new BulkRandomAccessFile(infile, "r"); mybrafout = new BulkRandomAccessFile(outfile, "rw"); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); //throw new InternalError("bad thing"); } Ti.barrier(); int numelem = len/8; long[1d] a = new long[0:numelem-1]; long[1d] b = new long[0:numelem-1]; long[1d] c = new long[0:numelem-1]; long[1d] bver = new long[0:numelem-1]; long[1d] cver = new long[0:numelem-1]; long [1d] single [1d] allb; long [1d] single [1d] allc; allb = new long [0:Ti.numProcs()-1][1d]; allc = new long [0:Ti.numProcs()-1][1d]; allb.exchange(b); allc.exchange(c); long [1d] otherb = allb[(Ti.thisProc()+1)%Ti.numProcs()]; long [1d] otherc = allc[(Ti.thisProc()+1)%Ti.numProcs()]; MSG("Reading local array.."); try { mybrafin.seek(0); a.readFrom(mybrafin); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } Ti.barrier(); MSG("Reading global array.."); try { mybrafin.seek(0); otherb.readFrom(mybrafin); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } Ti.barrier(); bver.copy(otherb); MSG("Verifying.."); for (int i=0; i < numelem; i++) { if (a[i] != bver[i]) { int first = i-5; int last = i+5; if (first < 0) first = 0; if (last >= numelem) last = numelem; for (int x = first; x < last; x++) MSG(" a[" + x + "]= " + a[x] + " bver[" + x + "]= " + bver[x]); MSG("Verification mismatch at element " + i); System.exit(1); } } MSG("Verified."); Ti.barrier(); MSG("Writing global array.."); try { mybrafout.seek(0); otherb.writeTo(mybrafout); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } MSG("Re-Reading global array.."); try { mybrafout.seek(0); otherc.readFrom(mybrafout); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } Ti.barrier(); cver.copy(otherc); MSG("Verifying.."); for (int i=0; i < numelem; i++) { if (a[i] != cver[i]) { int first = i-5; int last = i+5; if (first < 0) first = 0; if (last >= numelem) last = numelem; for (int x = first; x < last; x++) MSG(" a[" + x + "]= " + a[x] + " cver[" + x + "]= " + cver[x]); MSG("Verification mismatch at element " + i); System.exit(1); } } MSG("Verified."); Ti.barrier(); } { if (Ti.thisProc() == 0) MSG(" -------------- Beginning global non-contig array test.. -------------- "); BulkRandomAccessFile mybrafin; BulkRandomAccessFile mybrafout; try { if (outfile.exists()) outfile.delete(); mybrafin = new BulkRandomAccessFile(infile, "r"); mybrafout = new BulkRandomAccessFile(outfile, "rw"); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); //throw new InternalError("bad thing"); } Ti.barrier(); int numelem = len/8; long[2d] alloca = new long[0:numelem-1:1,0:2:1]; long[2d] allocb = new long[0:numelem-1:1,0:2:1]; long[2d] allocc = new long[0:numelem-1:1,0:2:1]; long[1d] a = alloca.slice(2,1); // get some non-contig arrays long[1d] b = allocb.slice(2,1); long[1d] c = allocc.slice(2,1); long[1d] bver = new long[0:numelem-1]; long[1d] cver = new long[0:numelem-1]; long [1d] single [1d] allb; long [1d] single [1d] allc; allb = new long [0:Ti.numProcs()-1][1d]; allc = new long [0:Ti.numProcs()-1][1d]; allb.exchange(b); allc.exchange(c); long [1d] otherb = allb[(Ti.thisProc()+1)%Ti.numProcs()]; long [1d] otherc = allc[(Ti.thisProc()+1)%Ti.numProcs()]; MSG("Reading local array.."); try { mybrafin.seek(0); a.readFrom(mybrafin); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } Ti.barrier(); MSG("Reading global array.."); try { mybrafin.seek(0); otherb.readFrom(mybrafin); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } Ti.barrier(); bver.copy(otherb); MSG("Verifying.."); for (int i=0; i < numelem; i++) { if (a[i] != bver[i]) { int first = i-5; int last = i+5; if (first < 0) first = 0; if (last >= numelem) last = numelem; for (int x = first; x < last; x++) MSG(" a[" + x + "]= " + a[x] + " bver[" + x + "]= " + bver[x]); MSG("Verification mismatch at element " + i); System.exit(1); } } MSG("Verified."); Ti.barrier(); MSG("Writing global array.."); try { mybrafout.seek(0); otherb.writeTo(mybrafout); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } MSG("Re-Reading global array.."); try { mybrafout.seek(0); otherc.readFrom(mybrafout); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); System.exit(1); } Ti.barrier(); cver.copy(otherc); MSG("Verifying.."); for (int i=0; i < numelem; i++) { if (a[i] != cver[i]) { int first = i-5; int last = i+5; if (first < 0) first = 0; if (last >= numelem) last = numelem; for (int x = first; x < last; x++) MSG(" a[" + x + "]= " + a[x] + " cver[" + x + "]= " + cver[x]); MSG("Verification mismatch at element " + i); System.exit(1); } } MSG("Verified."); Ti.barrier(); } } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); } try { Ti.barrier(); // cleanup if (outfile.exists()) outfile.delete(); } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); } } }