/* Description: non-blocking array-copy regression test * Copyright 2000, Dan Bonachea */ public class driver { public static single void main(String [] args) { tiArrayCopyTest.cmain(args); Ti.barrier(); javaArrayCopyTest.cmain(args); } } public class javaArrayCopyTest { public static single void cmain(String [] args) { try { if (Ti.thisProc() == 0) System.out.println("Running non-blocking JavaArray copy test on " + Ti.numProcs() + " processors"); testsize(1); testsize(32); testsize(256); testsize(2048); testsize(16384); testsize(131072); testsize(1048576); if (Ti.thisProc() == 0) System.out.println("done."); } catch (Exception exn) { System.err.println("P"+Ti.thisProc() + " got an exception: " + exn); System.exit(1); } } public static single void testsize(int size) { doit(size, "blocking", 1); doit(size, "non-blocking NB", 2); doit(size, "non-blocking NBI", 3); } public static single void doit(int size, String desc, int single type) { Ti.barrier(); if (Ti.thisProc() == 0) { System.out.println("size="+size*8 +" bytes "+ desc); System.out.flush(); } Ti.barrier(); long [] prvSrc = getArray(size, true); long [] prvDest = getArray(size, false); long [] sharedSrc = getArray(size, false); long [] sharedDest = getArray(size, false); if (type == 1) { // local -> local copy System.arraycopy(prvSrc, 0, sharedSrc, 0, size); verifyArray(sharedSrc, Ti.thisProc(), "local -> local", type); // local -> local copy, same array (identity transformation) System.arraycopy(prvSrc, 0, prvSrc, 0, size); verifyArray(prvSrc, Ti.thisProc(), "local -> local, same array", type); } else if (type == 2) { // local -> local copy Handle h1 = System.arraycopyNB(prvSrc, 0, sharedSrc, 0, size); // local -> local copy, same array (identity transformation) Handle h2 = System.arraycopyNB(prvSrc, 0, prvSrc, 0, size); h2.syncNB(); verifyArray(prvSrc, Ti.thisProc(), "local -> local, same array", type); h1.syncNB(); verifyArray(sharedSrc, Ti.thisProc(), "local -> local", type); } else { // local -> local copy System.arraycopyNBI(prvSrc, 0, sharedSrc, 0, size); // local -> local copy, same array (identity transformation) System.arraycopyNBI(prvSrc, 0, prvSrc, 0, size); Handle.syncNBI(); verifyArray(prvSrc, Ti.thisProc(), "local -> local, same array", type); verifyArray(sharedSrc, Ti.thisProc(), "local -> local", type); } Ti.barrier(); long [1d] single [] allSrc = new long [0 : Ti.numProcs()-1] []; long [1d] single [] allDest = new long [0 : Ti.numProcs()-1] []; allSrc.exchange(sharedSrc); allDest.exchange(sharedDest); int left = (Ti.thisProc() == 0?Ti.numProcs()-1:Ti.thisProc() - 1); int right = (Ti.thisProc() + 1) % Ti.numProcs(); if (type == 1) { // remote -> local System.arraycopy(allSrc[left], 0, prvDest, 0, size); verifyArray(prvDest, left, "remote -> local", type); // local -> remote System.arraycopy(prvSrc, 0, allDest[right], 0, size); Ti.barrier(); verifyArray(sharedDest, left, "local -> remote", type); Ti.barrier(); // remote -> remote (same owner) System.arraycopy(allSrc[right], 0, allDest[right], 0, size); Ti.barrier(); verifyArray(sharedDest, Ti.thisProc(), "remote -> remote (same owner)", type); Ti.barrier(); // remote -> remote (diff owners, when numProcs >= 3) System.arraycopy(allSrc[left], 0, allDest[right], 0, size); Ti.barrier(); int leftleft = (left == 0 ? Ti.numProcs()-1 : left - 1); verifyArray(sharedDest, leftleft, "remote -> remote (diff owner)", type); Ti.barrier(); } else if (type == 2) { // remote -> local Handle h1 = System.arraycopyNB(allSrc[left], 0, prvDest, 0, size); // local -> remote Handle h2 = System.arraycopyNB(prvSrc, 0, allDest[right], 0, size); h1.syncNB(); verifyArray(prvDest, left, "remote -> local", type); h2.syncNB(); Ti.barrier(); verifyArray(sharedDest, left, "local -> remote", type); Ti.barrier(); // remote -> remote (same owner) Handle h3 = System.arraycopyNB(allSrc[right], 0, allDest[right], 0, size); h3.syncNB(); Ti.barrier(); verifyArray(sharedDest, Ti.thisProc(), "remote -> remote (same owner)", type); Ti.barrier(); // remote -> remote (diff owners, when numProcs >= 3) Handle h4 = System.arraycopyNB(allSrc[left], 0, allDest[right], 0, size); h4.syncNB(); Ti.barrier(); int leftleft = (left == 0 ? Ti.numProcs()-1 : left - 1); verifyArray(sharedDest, leftleft, "remote -> remote (diff owner)", type); Ti.barrier(); } else { // remote -> local System.arraycopyNBI(allSrc[left], 0, prvDest, 0, size); // local -> remote System.arraycopyNBI(prvSrc, 0, allDest[right], 0, size); Handle.syncNBI(); verifyArray(prvDest, left, "remote -> local", type); Ti.barrier(); verifyArray(sharedDest, left, "local -> remote", type); Ti.barrier(); // remote -> remote (same owner) System.arraycopyNBI(allSrc[right], 0, allDest[right], 0, size); Handle.syncNBI(); Ti.barrier(); verifyArray(sharedDest, Ti.thisProc(), "remote -> remote (same owner)", type); Ti.barrier(); // remote -> remote (diff owners, when numProcs >= 3) System.arraycopyNBI(allSrc[left], 0, allDest[right], 0, size); Handle.syncNBI(); Ti.barrier(); int leftleft = (left == 0 ? Ti.numProcs()-1 : left - 1); verifyArray(sharedDest, leftleft, "remote -> remote (diff owner)", type); Ti.barrier(); } } public static long [] getArray(int size, boolean init) { // create an array of given size, initializing as necessary long [] arr = new long [size]; if (init) { int proc = Ti.thisProc(); for (int i=0; i < size; i++) { arr[i] = (((long)proc) << 32) | i; } } return arr; } public static void verifyArray(long [] arr, int proc, String location, int type) { for (int i=0; i < arr.length; i++) { if (arr[i] != ((((long)proc) << 32) | i)) { String typestr = "blocking"; if (type == 2) typestr = "non-blocking (NB)"; else if (type == 3) typestr = "non-blocking (NBI)"; System.err.println("P" + Ti.thisProc() + ": Array verification failed for " + location + " " + typestr +" array copy" + " at i=" + i + " arr[i] = " + "(" + ((arr[i] >> 32) & 0xFFFF) + ", " + (arr[i] & 0xFFFF) +")"); throw new InternalError("verification failed."); } } } } //------------------------------------------------------------------------------------ public class tiArrayCopyTest { public static single void cmain(String [] args) { try { if (Ti.thisProc() == 0) System.out.println("Running non-blocking TiArray copy test on " + Ti.numProcs() + " processors"); testsize(1); testsize(32); testsize(256); testsize(2048); testsize(16384); if (Ti.thisProc() == 0) System.out.println("done."); } catch (Exception exn) { System.err.println("P"+Ti.thisProc() + " got an exception: " + exn); System.exit(1); } } public static single void testsize(int size) { String desc[] = { "blocking", "NB ", "NBI " } ; for (int single type = 1; type <= 3; type++) { doit(type, size, 0, 0, desc[type-1]+" contiguous"); doit(type, size, 2, 0, desc[type-1]+" non-contiguous, fixed"); doit(type, size, Ti.thisProc()+2, 0, desc[type-1]+" non-contiguous, proc-dependent"); doit(type, size, Ti.thisProc()+2, 1, desc[type-1]+" non-contiguous, proc-dependent, array-dependent"); } } public static single void doit(int single type, int size, int slicefactor, int slicebump, String desc) { Ti.barrier(); if (Ti.thisProc() == 0) { System.out.println("size="+size*8 +" bytes "+ desc); System.out.flush(); } Ti.barrier(); long [1d] prvSrc = getArray(size, slicefactor + 1*slicebump, true); long [1d] prvDest = getArray(size, slicefactor + 2*slicebump, false); long [1d] sharedSrc = getArray(size, slicefactor + 3*slicebump, false); long [1d] sharedDest = getArray(size, slicefactor + 4*slicebump, false); Handle myhandle; #define COPY_INIT(lhs, rhs) do { \ if (type == 1) { \ lhs.copy(rhs); \ } else if (type == 2) { \ myhandle = lhs.copyNB(rhs); \ } else { \ lhs.copyNBI(rhs); \ } \ } while (false) #define COPY_SYNC() do { \ if (type == 1) { \ /* noop */; \ } else if (type == 2) { \ myhandle.syncNB(); \ } else { \ Handle.syncNBI(); \ } \ } while (false) // local -> local copy COPY_INIT(sharedSrc,prvSrc); COPY_SYNC(); verifyArray(sharedSrc, Ti.thisProc(), "local -> local"); Ti.barrier(); // local -> local copy, same array (identity transformation) COPY_INIT(prvSrc,prvSrc); COPY_SYNC(); verifyArray(prvSrc, Ti.thisProc(), "local -> local, same array"); Ti.barrier(); // local -> local copy, restricted (identity transformation) RectDomain<1> interiorpts = prvSrc.domain().shrink(1); COPY_INIT(prvSrc,prvSrc.restrict(interiorpts)); COPY_SYNC(); verifyArray(prvSrc, Ti.thisProc(), "local -> local, same array restricted"); Ti.barrier(); long [1d] single [1d] allSrc = new long [0 : Ti.numProcs()-1] [1d]; long [1d] single [1d] allDest = new long [0 : Ti.numProcs()-1] [1d]; allSrc.exchange(sharedSrc); allDest.exchange(sharedDest); int left = (Ti.thisProc() == 0?Ti.numProcs()-1:Ti.thisProc() - 1); int right = (Ti.thisProc() + 1) % Ti.numProcs(); if (type == 1) { // remote -> local prvDest.copy(allSrc[left]); verifyArray(prvDest, left, "remote -> local"); // local -> remote allDest[right].copy(prvSrc); } else if (type == 2) { // remote -> local Handle h1 = prvDest.copyNB(allSrc[left]); // local -> remote Handle h2 = allDest[right].copyNB(prvSrc); h1.syncNB(); verifyArray(prvDest, left, "remote -> local"); h2.syncNB(); } else { // remote -> local prvDest.copyNBI(allSrc[left]); // local -> remote allDest[right].copyNBI(prvSrc); Handle.syncNBI(); verifyArray(prvDest, left, "remote -> local"); } Ti.barrier(); verifyArray(sharedDest, left, "local -> remote"); Ti.barrier(); // remote -> remote (same owner) COPY_INIT(allDest[right],allSrc[right]); COPY_SYNC(); Ti.barrier(); verifyArray(sharedDest, Ti.thisProc(), "remote -> remote (same owner)"); Ti.barrier(); // remote -> remote (diff owners, when numProcs >= 3) COPY_INIT(allDest[right],allSrc[left]); COPY_SYNC(); Ti.barrier(); int leftleft = (left == 0 ? Ti.numProcs()-1 : left - 1); verifyArray(sharedDest, leftleft, "remote -> remote (diff owner)"); Ti.barrier(); } public static long [1d] getArray(int size, int slicefactor, boolean init) { // create an array of given size, initializing as necessary long [1d] arr = null; if (slicefactor <= 1) { arr = new long [0:size-1:1]; } else { long [2d] arr2 = new long [0:size-1:1, 0:slicefactor-1:1]; arr = arr2.slice(2, 1); } if (init) { int proc = Ti.thisProc(); for (int i=0; i < size; i++) { arr[i] = (((long)proc) << 32) | i; } } return arr; } public static void verifyArray(long [1d] arr, int proc, String location) { for (int i=0; i < arr.domain().size()-1; i++) { if (arr[i] != ((((long)proc) << 32) | i)) { System.err.println("P" + Ti.thisProc() + ": Array verification failed for " + location + " array copy" + " at i=" + i + " arr[i] = " + "(" + ((arr[i] >> 32) & 0xFFFF) + ", " + (arr[i] & 0xFFFF) +")"); throw new InternalError("verification failed."); } } } }