def test_non_overlapping_get(self): chunks_per_process = self.dataset.chunk_grid[0] // mpi_size() x_start = mpi_rank() * chunks_per_process * DATA_CHUNK_SIZE[0] if mpi_rank() == mpi_size() - 1: x_stop = self.dataset.shape[0] else: x_stop = (mpi_rank() + 1) * chunks_per_process * DATA_CHUNK_SIZE[0] if x_start < self.dataset.shape[0]: np.testing.assert_array_equal(self.dataset[x_start:x_stop, ...], self.data[x_start:x_stop, ...]) mpi_barrier()
def get_output_dataset(): # only one node should create results dname = '{}/{}'.format(backend.name, mpi_size()) fname = join(OUT_PATH, 'result.h5') shape = (len(DATA_SIZE), len(CHUNK_SIZE), 3, NTESTS) with h5.File(fname, 'a') as g: if dname in g: if g[dname].shape != shape: raise ValueError('Dataset exists with invalid shape') else: g.create_dataset(dname, shape=shape, dtype=np.float32) g[dname].attrs['axis0_label'] = 'Data Size' g[dname].attrs['axis1_label'] = 'Chunk Size' g[dname].attrs['axis2_label'] = 'Tests' g[dname].attrs['axis3_label'] = '# Tests' g[dname].attrs['axis0_value'] = DATA_SIZE g[dname].attrs['axis1_value'] = CHUNK_SIZE g[dname].attrs['axis2_value'] = np.array(['DATA', '3D', '1D'], dtype='S4') g[dname].attrs['axis3_value'] = list(range(NTESTS)) h5out = h5.File(fname, 'a') h5result = h5out[dname] return h5out, h5result
def test_non_overlapping_set(self): chunks_per_process = self.dataset.chunk_grid[0] // mpi_size() x_start = mpi_rank() * chunks_per_process * DATA_CHUNK_SIZE[0] if mpi_rank() == mpi_size() - 1: x_stop = self.dataset.shape[0] else: x_stop = (mpi_rank() + 1) * chunks_per_process * DATA_CHUNK_SIZE[0] if x_start < self.dataset.shape[0]: self.dataset[x_start:x_stop, ...] = \ self.data[x_start:x_stop, ...] * 3 + 5 mpi_barrier() if mpi_is_root(): expected = self.data * 3 + 5 result = self.dataset[...] np.testing.assert_array_equal(result, expected) mpi_barrier()
def setUp(self): if ENGINE == 'mpi' and mpi_size() > 1: self.skipTest("This should not test concurrent access") log.info('DatasetTest: %s, %s, %s', BACKEND, ENGINE, CONNECTION_CONFIG) self.fake_dataset = 'NotADataset' self.data = np.random.random_integers(DATASET_NUMBER_RANGE[0], DATASET_NUMBER_RANGE[1], DATA_SIZE) self.dataset = self.connection_handle.create_dataset( self.fake_dataset, data=self.data, chunk_size=DATA_CHUNK_SIZE)
def convolve1(ds, sigma): mpi_barrier() pprint('Convolving in 3D', rank=0) with MpiTimer('Separable 3D convolution') as T: ds3d_ = ds.clone('gaussian_3d') for z in range(mpi_rank(), ds.chunk_grid[0], mpi_size()): zS = z * ds.chunk_size[0] zE = min(zS + ds.chunk_size[0], ds.shape[0]) for y in range(ds.chunk_grid[1]): yS = y * ds.chunk_size[1] yE = min(yS + ds.chunk_size[1], ds.shape[1]) for x in range(ds.chunk_grid[2]): xS = x * ds.chunk_size[2] xE = min(xS + ds.chunk_size[2], ds.shape[2]) out = gaussian_filter(ds[zS:zE, yS:yE, xS:xE], sigma=sigma) ds3d_[zS:zE, yS:yE, xS:xE] = out mpi_barrier() if mpi_root(): try: imsave( join( OUT_PATH, 'conv3d_{}-{}-{}.png'.format(mpi_size(), ds.shape[0], ds.chunk_size[0])), ds3d_[ds.shape[0] // 2]) except NameError: pass mpi_barrier() ds3d_.delete() return T.time
def setUp(self): if ENGINE != "mpi" or mpi_size() < 2: self.skipTest("Test for engine mpi with several processes") if BACKEND == "ram": self.skipTest("Concurrent access in backend ram is not supported") log.info('DatasetTest: %s, %s, %s', BACKEND, ENGINE, CONNECTION_CONFIG) self.fake_dataset = 'NotADataset' data = None if mpi_is_root(): data = np.random.random_integers(DATASET_NUMBER_RANGE[0], DATASET_NUMBER_RANGE[1], DATA_SIZE) self.data = mpi_comm().bcast(data, root=0) self.dataset = self.connection_handle.create_dataset( self.fake_dataset, data=self.data, chunk_size=DATA_CHUNK_SIZE)
h5in = h5.File(fname, 'r') h5data = h5in['data'] ############################################################################### with MpiTimer('DosNa %s (%s)' % (engine.name, backend.name)): with dn.Cluster('/tmp/') as C: with C.create_pool('test_dosna') as P: data = P.create_dataset('test_data', data=h5data, chunks=(CS, CS, CS)) for start in range(mpi_rank() * CS, DS, mpi_size() * CS): stop = start + CS i = start j = min(stop, DS) np.testing.assert_allclose(data[i:j], h5data[i:j]) for start in range(mpi_rank() * CS, DS, mpi_size() * CS): stop = start + CS i = start j = min(stop, DS) np.testing.assert_allclose(data[:, i:j], h5data[:, i:j]) for start in range(mpi_rank() * CS, DS, mpi_size() * CS): stop = start + CS i = start j = min(stop, DS)
def convolve2(ds, sigma): mpi_barrier() with MpiTimer('Three separable 1D convolutions') as T: pprint('Convolving axis Z', rank=0) ds1_ = ds.clone('gaussian_z') for z in range(mpi_rank(), ds.chunk_grid[0], mpi_size()): zS = z * ds.chunk_size[0] zE = min(zS + ds.chunk_size[0], ds.shape[0]) out = gaussian_filter1d(ds[zS:zE], sigma=sigma, axis=0) ds1_[zS:zE] = out mpi_barrier() # Gaussian second axis pprint('Convolving axis Y', rank=0) ds2_ = ds.clone('gaussian_y') for y in range(mpi_rank(), ds.chunk_grid[1], mpi_size()): yS = y * ds.chunk_size[1] yE = min(yS + ds.chunk_size[1], ds.shape[1]) out = gaussian_filter1d(ds1_[:, yS:yE], sigma=sigma, axis=1) ds2_[:, yS:yE] = out mpi_barrier() # Gaussian second axis pprint('Convolving axis X', rank=0) ds3_ = ds.clone('gaussian_x') for x in range(mpi_rank(), ds.chunk_grid[2], mpi_size()): xS = x * ds.chunk_size[2] xE = min(xS + ds.chunk_size[2], ds.shape[2]) out = gaussian_filter1d(ds2_[..., xS:xE], sigma=sigma, axis=2) ds3_[..., xS:xE] = out mpi_barrier() if mpi_root(): try: imsave( join( OUT_PATH, 'conv3x1d_{}-{}-{}.png'.format(mpi_size(), ds.shape[0], ds.chunk_size[0])), ds3_[ds.shape[0] // 2]) except NameError: pass mpi_barrier() ds1_.delete() ds2_.delete() ds3_.delete() return T.time