def test_test3(self): """ 1D, int """ dtyp = numpy.int64 # MPI stuff comm = MPI.COMM_WORLD rk = comm.Get_rank() sz = comm.Get_size() # create the dist array n = 10 da = distarray.ghZeros( (n,), dtyp, ghostWidth=1 ) # set data da[:] = 100*rk + numpy.array([i for i in range(n)], dtyp) # access remote data leftRk = (rk - 1) % sz print 'proc %d tries to access data from %d' % (rk, leftRk) leftData = da.get(pe=leftRk, winID=(1,)) print 'leftData for rank %d = %s' % (rk, str(leftData)) # check if leftRk < rk: self.assertEqual(leftData[0], da[-1] - 100) else: self.assertEqual(leftData[0], da[-1] + 100*(sz-1)) # free da.free()
def test_test3(self): """ 1D, int """ dtyp = numpy.int64 # MPI stuff comm = MPI.COMM_WORLD rk = comm.Get_rank() sz = comm.Get_size() # create the dist array n = 10 da = distarray.ghZeros((n, ), dtyp, ghostWidth=1) # set data da[:] = 100 * rk + numpy.array([i for i in range(n)], dtyp) # access remote data leftRk = (rk - 1) % sz print 'proc %d tries to access data from %d' % (rk, leftRk) leftData = da.get(pe=leftRk, winID=(1, )) print 'leftData for rank %d = %s' % (rk, str(leftData)) # check if leftRk < rk: self.assertEqual(leftData[0], da[-1] - 100) else: self.assertEqual(leftData[0], da[-1] + 100 * (sz - 1)) # free da.free()
def test_test0(self): """ Test constructors """ da = distarray.ghZeros( (2,3), numpy.float64 ) da.free() da = distarray.ghOnes( (2,3), numpy.float64 ) da.free() da = distarray.ghArray( [1,2,3] ) da.free()
def test_test0(self): """ Test constructors """ da = distarray.ghZeros((2, 3), numpy.float64) da.free() da = distarray.ghOnes((2, 3), numpy.float64) da.free() da = distarray.ghArray([1, 2, 3]) da.free()
def getLaplacian(self, x0s, ls, plot=False): """ Compute the discretized Laplacian @param x0s lower corner coordinates along each dimension @param ls pe domain sizes along each dimension @param plot True if want to show plot @return discretized Laplacian in local pe domain """ self.hs = [ls[i] / float(self.n) for i in range(self.ndim)] self.ls = ls self.x0s = x0s # set input data values shp = (self.n, self.n) data = numpy.zeros(shp, numpy.float64) for j in range(self.n): y = x0s[0] + ls[0] * (j + 0.5) / float(self.n) for i in range(self.n): x = x0s[1] + ls[1] * (i + 0.5) / float(self.n) data[j, i] = self.funct(x, y) # create MPI windows and attach data inData = distarray.ghZeros(shp, numpy.float64, ghostWidth=1) # set local domain values inData[:] = data # compute the Laplacian res = numpy.zeros(shp, numpy.float64) for dim in range(self.ndim): # iterate over dimensions (or windows) # inner nodes, no communication necessary c = inData.getSlab(dim, slice(1, self.n - 1)) # center p = inData.getSlab(dim, slice(2, self.n)) # plus m = inData.getSlab(dim, slice(0, self.n - 2)) # minus res[c] += inData[p] + inData[m] - 2.0 * inData[c] # slabs that require communication # lo c = inData.getSlab(dim, slice(0, 1)) p = inData.getSlab(dim, slice(1, 2)) neighPe = self.neighbors[dim]['-'] outsidePhysDom = False if neighPe < 0: # no data transfer if out of physical domain neighPe = self.myid outsidePhysDom = True # collective (all pes) winIndex = [0 for i in range(self.ndim)] winIndex[dim] = +1 # hi side for neighbor remoteData = inData.get(neighPe, winID=tuple(winIndex)) remoteData = numpy.reshape(remoteData, inData[p].shape) if not outsidePhysDom: res[c] += inData[p] + remoteData - 2.0 * inData[c] # hi c = inData.getSlab(dim, slice(self.n - 1, self.n)) m = inData.getSlab(dim, slice(self.n - 2, self.n - 1)) neighPe = self.neighbors[dim]['+'] outsidePhysDom = False if neighPe >= self.npes: # no data transfer if out of physical domain neighPe = self.myid outsidePhysDom = True # collective (all pes) winIndex = [0 for i in range(self.ndim)] winIndex[dim] = -1 # lo side for neighbor remoteData = inData.get(neighPe, winID=tuple(winIndex)) remoteData = numpy.reshape(remoteData, inData[m].shape) if not outsidePhysDom: res[c] += remoteData + inData[m] - 2.0 * inData[c] inData.free() # must explicitly free windows if plot: import re import os # save data in file, one per pe, then combine data fname = 'mvLaplacianTest_rk%d.txt' % self.myid numpy.savetxt(fname, res, fmt='%12.6g') self.comm.barrier() if self.myid == 0: self.show('mvLaplacianTest_rk*.txt') return res
def getLaplacian(self, x0s, ls, plot = False): """ Compute the discretized Laplacian @param x0s lower corner coordinates along each dimension @param ls pe domain sizes along each dimension @param plot True if want to show plot @return discretized Laplacian in local pe domain """ self.hs = [ls[i]/float(self.n) for i in range(self.ndim)] self.ls = ls self.x0s = x0s # set input data values shp = (self.n, self.n) data = numpy.zeros(shp, numpy.float64) for j in range(self.n): y = x0s[0] + ls[0]*(j + 0.5)/float(self.n) for i in range(self.n): x = x0s[1] + ls[1]*(i + 0.5)/float(self.n) data[j, i] = self.funct(x, y) # create MPI windows and attach data inData = distarray.ghZeros(shp, numpy.float64, ghostWidth=1) # set local domain values inData[:] = data # compute the Laplacian res = numpy.zeros(shp, numpy.float64) for dim in range(self.ndim): # iterate over dimensions (or windows) # inner nodes, no communication necessary c = inData.getSlab(dim, slice(1, self.n-1)) # center p = inData.getSlab(dim, slice(2, self.n )) # plus m = inData.getSlab(dim, slice(0, self.n-2)) # minus res[c] += inData[p] + inData[m] - 2.0*inData[c] # slabs that require communication # lo c = inData.getSlab(dim, slice(0, 1)) p = inData.getSlab(dim, slice(1, 2)) neighPe = self.neighbors[dim]['-'] outsidePhysDom = False if neighPe < 0: # no data transfer if out of physical domain neighPe = self.myid outsidePhysDom = True # collective (all pes) winIndex = [0 for i in range(self.ndim)] winIndex[dim] = +1 # hi side for neighbor remoteData = inData.get(neighPe, winID=tuple(winIndex)) remoteData = numpy.reshape(remoteData, inData[p].shape) if not outsidePhysDom: res[c] += inData[p] + remoteData - 2.0*inData[c] # hi c = inData.getSlab(dim, slice(self.n-1, self.n )) m = inData.getSlab(dim, slice(self.n-2, self.n-1)) neighPe = self.neighbors[dim]['+'] outsidePhysDom = False if neighPe >= self.npes: # no data transfer if out of physical domain neighPe = self.myid outsidePhysDom = True # collective (all pes) winIndex = [0 for i in range(self.ndim)] winIndex[dim] = -1 # lo side for neighbor remoteData = inData.get(neighPe, winID=tuple(winIndex)) remoteData = numpy.reshape(remoteData, inData[m].shape) if not outsidePhysDom: res[c] += remoteData + inData[m] - 2.0*inData[c] inData.free() # must explicitly free windows if plot: import re import os # save data in file, one per pe, then combine data fname = 'mvLaplacianTest_rk%d.txt' % self.myid numpy.savetxt(fname, res, fmt = '%12.6g') self.comm.barrier() if self.myid == 0: self.show('mvLaplacianTest_rk*.txt') return res