import java.io.*; public class taraftest { public static long starttime; public static void MSG(String s) { System.out.println((System.currentTimeMillis() - starttime) / 1000.0 + ": " + s); } public static single void main (String single [] single args) { if (args.length != 2) { if (Ti.thisProc() == 0) System.out.println("Usage: taraftest "); Ti.barrier(); System.exit(1); } String infilename = args[0]; File infile = new File(infilename); String type = args[1]; String outfilename = "taraftest.tmp." + Ti.thisProc(); File outfile = new File(outfilename); starttime = System.currentTimeMillis(); MSG("File size is: " + infile.length()); int len = (int)infile.length(); try { RandomAccessFile brafin = new RandomAccessFile(infile, "r"); MSG("File size is: " + brafin.length()); int len = (int)brafin.length(); // Java sucks //------------------------------------------------------------------------------------ if (type.indexOf("long1d") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning long1d test.. -------------- "); int numelem = len / 8; RectDomain<1> mydom = [1:numelem:1]; long [1d] a = new long[mydom]; long [1d] b = new long[mydom]; MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); foreach (p in mydom) { if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p); } } MSG("Verified"); } //------------------------------------------------------------------------------------ if (type.indexOf("long3d") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning long3d test.. -------------- "); RectDomain<3> mydom = [10:30:1,11:100:5,0:15:4]; long [3d] a = new long[mydom]; long [3d] b = new long[mydom]; MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); foreach (p in mydom) { if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p); } } MSG("Verified"); } //------------------------------------------------------------------------------------ if (type.indexOf("byte3d") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning byte3d test.. -------------- "); RectDomain<3> mydom = [10:30:1,11:100:5,0:15:4]; byte [3d] a = new byte[mydom]; byte [3d] b = new byte[mydom]; MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); foreach (p in mydom) { if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p); } } MSG("Verified"); } //------------------------------------------------------------------------------------ if (type.indexOf("float3d") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning float3d test.. -------------- "); RectDomain<3> mydom = [10:30:1,11:100:5,0:15:4]; float [3d] a = new float[mydom]; float [3d] b = new float[mydom]; MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); foreach (p in mydom) { if (a[p] != b[p] && !Float.isNaN(a[p]) && !Float.isNaN(b[p])) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Integer.toHexString(Float.floatToIntBits(a[p])) + " b[" + p + "]= 0x" + Integer.toHexString(Float.floatToIntBits(b[p]))); throw new InternalError("Verification mismatch at element " + p); } } MSG("Verified"); } //------------------------------------------------------------------------------------ if (type.indexOf("sliced") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning sliced test.. -------------- "); int numelem = len / 8; if (numelem < 1000) { MSG("INPUT FILE TOO SMALL FOR THIS TEST"); } else { RectDomain<3> bigdom = [1:10:1,200:400:2,40:80:4]; long [3d] abig = new long[bigdom]; long [3d] bbig = new long[bigdom]; { MSG(" -------------- sliced test 1 "); RectDomain<2> mydom = [200:400:2,40:80:4]; long [2d] a = abig.slice(1,5); long [2d] b = bbig.slice(1,5); MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); int elemcount=0; foreach (p in mydom) { elemcount++; if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p + " (processed " + elemcount + " elements)"); } } MSG("Verified "); } { MSG(" -------------- sliced test 2 "); RectDomain<2> mydom = [1:10:1,40:80:4]; long [2d] a = abig.slice(2,228); long [2d] b = bbig.slice(2,228); MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); int elemcount=0; foreach (p in mydom) { elemcount++; if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p + " (processed " + elemcount + " elements)"); } } MSG("Verified "); } { MSG(" -------------- sliced test 3 "); RectDomain<2> mydom = [1:10:1,200:400:2]; long [2d] a = abig.slice(3,48); long [2d] b = bbig.slice(3,48); if (a.domain() != mydom || b.domain() != mydom) { MSG("domain mismatch"); throw new InternalError("domain mismatch"); } MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); int elemcount=0; foreach (p in mydom) { elemcount++; if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p + " (processed " + elemcount + " elements)"); } } MSG("Verified "); } } } //------------------------------------------------------------------------------------ if (type.indexOf("restrict") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning restrict test.. -------------- "); int numelem = len / 8; if (numelem < 1000) { MSG("INPUT FILE TOO SMALL FOR THIS TEST"); } else { RectDomain<3> bigdom = [1:10:1,200:400:2,40:80:4]; RectDomain<3> mydom = [2:8:1,200:400:10,60:80:4]; long [3d] abig = new long[bigdom]; long [3d] bbig = new long[bigdom]; long [3d] a = abig.restrict(mydom); long [3d] b = bbig.restrict(mydom); MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); foreach (p in mydom) { if (a[p] != b[p]) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); MSG(" a[" + p + "]= 0x" + Long.toHexString(a[p]) + " b[" + p + "]= 0x" + Long.toHexString(b[p])); throw new InternalError("Verification mismatch at element " + p); } } MSG("Verified "); } } //------------------------------------------------------------------------------------ if (type.indexOf("crazy") >= 0 || type.indexOf("all") >= 0) { if (outfile.exists()) outfile.delete(); RandomAccessFile brafout = new RandomAccessFile(outfile, "rw"); MSG(" -------------- Beginning crazy test.. -------------- "); int numelem = len / 8; if (numelem < 20000) { MSG("INPUT FILE TOO SMALL FOR THIS TEST"); } else { RectDomain<3> bigdom = [50:90:2,400:600:2,40:80:4]; RectDomain<3> mydomr = [60:80:10,400:500:4,60:80:4]; RectDomain<2> mydoms = [60:80:10,400:500:4]; RectDomain<2> mydom = [120:160:20,1200:1500:12]; double [3d] abig = new double[bigdom]; double [3d] bbig = new double[bigdom]; double [3d] ar = abig.restrict(mydomr); double [3d] br = bbig.restrict(mydomr); double [2d] as = ar.slice(3,68); double [2d] bs = br.slice(3,68); double [2d] a = as.inject([2,3]); double [2d] b = as.inject([2,3]); MSG("Seeking.."); brafin.seek(0); MSG("Reading.."); a.readFrom(brafin); brafout.seek(0); MSG("Writing.."); a.writeTo(brafout); MSG("Re-reading.."); brafout.seek(0); b.readFrom(brafout); MSG("Verifying.."); foreach (p in mydom) { if (a[p] != b[p] && !Double.isNaN(a[p]) && !Double.isNaN(b[p])) { MSG(" a[" + p + "]= " + a[p] + " b[" + p + "]= " + b[p]); throw new InternalError("Verification mismatch at element " + p); } } MSG("Verified "); } } //------------------------------------------------------------------------------------ } catch (Throwable exn) { MSG("caught " + ExnType.gettype(exn) + " : " + exn.getMessage()); } } }