/* This file contains tests for array copy for arrays that are non-contiguous over the intersection domain. Jimmy Su 9/30/2002 */ public class NonContiguousArrayCopy{ private static single void arraycopy2Dtest1(){ double [2d] src; double [2d] localSrc; double [2d] dest = new double[[3,3]:[15,15]:[4,2]]; int count = 0; /* packing should use memcpy unpacking should use element by element copy */ if (Ti.thisProc() == 0){ localSrc = new double[[1,1]:[17,17]:[2,4]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } } src = broadcast localSrc from 0; dest.copy(src); foreach (p in (dest.domain() * src.domain())){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } Ti.barrier(); /* packing should use element by element copy unpacking should use memcpy */ dest = new double[[3,3]:[15,15]:[2,4]]; count = 0; if (Ti.thisProc() == 0){ localSrc = new double[[1,1]:[17,17]:[4,2]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } } src = broadcast localSrc from 0; dest.copy(src); foreach (p in (dest.domain()*src.domain())){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } Ti.barrier(); /* both packing and unpacking should use element by element copy */ dest = new double[[1,1]:[13,13]:[3,3]]; count = 0; if (Ti.thisProc() == 0){ localSrc = new double[[1,1]:[17,17]:[2,2]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } } src = broadcast localSrc from 0; dest.copy(src); foreach (p in (dest.domain() * src.domain())){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } } private static single void arraycopy2Dtest2(){ double [2d] src; double [2d] localSrc; double [2d] dest = new double[[3,3]:[15,15]:[2,2]]; double [3d] array3D; int count = 0; if (Ti.thisProc() == 0){ localSrc = new double[[1,1]:[17,17]:[2,2]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } array3D = new double[[1,1,1]:[17,17,17]:[2,2,2]]; foreach (p in array3D.domain()){ array3D[p] = count; count++; } } src = broadcast localSrc from 0; /* arrays are not contiguous over intersection domain but elements along last dimension are contiguous should use the memcpy version for pack and unpack */ dest.copy(src); foreach (p in dest.domain()){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } System.out.flush(); Ti.barrier(); dest.set(0); if (Ti.thisProc() == 0){ localSrc = array3D.slice(1,3); } src = broadcast localSrc from 0; /* arrays are not contiguous over intersection domain but elements along last dimension are contiguous should use the memcpy version for pack and unpack */ dest.copy(src); foreach (p in dest.domain()){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } System.out.flush(); Ti.barrier(); dest.set(0); if (Ti.thisProc() == 0){ localSrc = array3D.slice(2,3); } src = broadcast localSrc from 0; /* arrays are not contiguous over intersection domain but elements along last dimension are contiguous should use the memcpy version for pack and unpack */ dest.copy(src); foreach (p in dest.domain()){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } System.out.flush(); Ti.barrier(); dest.set(0); if (Ti.thisProc() == 0){ localSrc = array3D.slice(3,3); } src = broadcast localSrc from 0; /* arrays are not contiguous over intersection domain and elements along last dimension are not contiguous should use the element by element copy in pack and unpack */ dest.copy(src); foreach (p in dest.domain()){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } System.out.flush(); } private static single void arraycopy2Dtest3(){ long [2d] src; long [2d] localSrc; long [2d] dest = new long[[1,1]:[50,50]:[1,1]]; int count = 0; long foo = 0x1234567807651234L; dest.set(foo); if (Ti.thisProc() == 0){ localSrc = new long[[4,4]:[17,17]:[1,1]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } } src = broadcast localSrc from 0; /* one array not contiguous over intersection domain but elements along last dimension are contiguous should use the memcpy version for pack and unpack */ dest.copy(src); foreach (p in src.domain()){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } /* check we didn't trash surrounding memory */ foreach (p in dest.domain() - src.domain()){ if (dest[p] != foo){ System.err.println("Error in array copy"); System.exit(1); } } System.out.flush(); Ti.barrier(); } private static single void arraycopy3Dtest1(){ double [3d] src; double [3d] localSrc; double [3d] dest = new double[[3,3,3]:[15,15,15]:[2,4,2]]; int count = 0; if (Ti.thisProc() == 0){ localSrc = new double[[1,1,1]:[17,17,17]:[4,2,4]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } } src = broadcast localSrc from 0; /* arrays are not contiguous over intersection domain but elements along last dimension are contiguous pack should use memcpy and unpack should use element by element copy */ dest.copy(src); foreach (p in (dest.domain() * src.domain())){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } Ti.barrier(); dest = new double[[3,3,3]:[15,15,15]:[2,2,2]]; count = 0; if (Ti.thisProc() == 0){ localSrc = new double[[1,1,1]:[17,17,17]:[2,2,2]]; foreach (p in localSrc.domain()){ localSrc[p] = count; count++; } } dest.set(0); double [3d] permuteArray; if (Ti.thisProc() == 0){ permuteArray = localSrc.permute([2,1,3]); } src = broadcast permuteArray from 0; /* arrays are not contiguous over intersection domain but elements along last dimension are contiguous should use the memcpy version for pack and unpack */ dest.copy(src); foreach (p in (dest.domain() * src.domain())){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } Ti.barrier(); dest.set(0); dest = dest.permute([2,1,3]); /* arrays are not contiguous over intersection domain but elements along last dimension are contiguous should use the memcpy version for pack and unpack */ dest.copy(src); foreach (p in (dest.domain() * src.domain())){ if (dest[p] != src[p]){ System.err.println("Error in array copy"); System.exit(1); } } } public static single void main(String[] args){ arraycopy2Dtest1(); arraycopy2Dtest2(); arraycopy2Dtest3(); arraycopy3Dtest1(); System.out.println("done."); } }