/* Description: Titanium array-copy regression test * Copyright 2000, Dan Bonachea */ public class arrayCopyTest { public static single void main(String [] args) { try { if (Ti.thisProc() == 0) System.out.println("Running array 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) { doit(size, 0, 0, "contiguous"); doit(size, 2, 0, "non-contiguous, fixed"); doit(size, Ti.thisProc()+2, 0, "non-contiguous, proc-dependent"); doit(size, Ti.thisProc()+2, 1, "non-contiguous, proc-dependent, array-dependent"); } public static single void doit(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); // local -> local copy sharedSrc.copy(prvSrc); verifyArray(sharedSrc, Ti.thisProc(), "local -> local"); Ti.barrier(); // local -> local copy, same array (identity transformation) prvSrc.copy(prvSrc); verifyArray(prvSrc, Ti.thisProc(), "local -> local, same array"); Ti.barrier(); // local -> local copy, restricted (identity transformation) RectDomain<1> interiorpts = prvSrc.domain().shrink(1); prvSrc.copy(prvSrc.restrict(interiorpts)); 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(); // remote -> local prvDest.copy(allSrc[left]); verifyArray(prvDest, left, "remote -> local"); Ti.barrier(); // local -> remote allDest[right].copy(prvSrc); Ti.barrier(); verifyArray(sharedDest, left, "local -> remote"); Ti.barrier(); // remote -> remote (same owner) allDest[right].copy(allSrc[right]); Ti.barrier(); verifyArray(sharedDest, Ti.thisProc(), "remote -> remote (same owner)"); Ti.barrier(); // remote -> remote (diff owners, when numProcs >= 3) allDest[right].copy(allSrc[left]); 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."); } } } }