def gather(s, nums, source, vanilla=0): """Wrapper for easy MPI Gather receive. Receive data from source with tag. Create appropriate buffer and receive data. """ control_info = get_control_info(s) protocol = control_info[0] typecode = control_info[1] s_size = nums if protocol == 'array': import Numeric x = Numeric.zeros(s_size * size(), typecode) gather_array(s, s_size, x, source) elif protocol == 'string': x = ' ' * s_size * size() gather_string(s, s_size, x, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for gather" % protocol else: raise "Unknown values for protocol: %s" % protocol return x
def raw_gather(s, nums, d, source, vanilla=0): """Wrapper for MPI gather. Gather s in nums element to d (of the same nums size) from source. Automatically determine appropriate protocol and call corresponding send function. The variable s can be any (picklable) type, but Numeric variables and text strings will most efficient. Setting vanilla = 1 forces vanilla mode for any type. """ protocol = get_control_info(s, vanilla)[0] if protocol == 'array': gather_array(s, nums, d, source) elif protocol == 'string': gather_string(s, nums, d, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for gather" % protocol else: raise "Unknown values for protocol: %s" % protocol return d
def apply_patch_for_similarities(params, extension): if not test_patch_for_similarities(params, extension): file_out_suff = params.get('data', 'file_out_suff') hdf5_compress = params.getboolean('data', 'hdf5_compress') blosc_compress = params.getboolean('data', 'blosc_compress') N_tm = io.load_data(params, 'nb_templates', extension) N_half = int(N_tm // 2) N_t = params.getint('detection', 'N_t') duration = 2 * N_t - 1 if comm.rank == 0: print_and_log(["Fixing overlaps from 0.5.XX..."], 'default', logger) maxlag = numpy.zeros((N_half, N_half), dtype=numpy.int32) maxoverlap = numpy.zeros((N_half, N_half), dtype=numpy.float32) to_explore = numpy.arange(N_half - 1)[comm.rank::comm.size] if comm.rank == 0: to_explore = get_tqdm_progressbar(to_explore) if not SHARED_MEMORY: over_x, over_y, over_data, over_shape = io.load_data( params, 'overlaps-raw', extension=extension) else: over_x, over_y, over_data, over_shape = io.load_data_memshared( params, 'overlaps-raw', extension=extension) for i in to_explore: idx = numpy.where((over_x >= i * N_tm + i + 1) & (over_x < (i * N_tm + N_half)))[0] local_x = over_x[idx] - (i * N_tm + i + 1) data = numpy.zeros((N_half - (i + 1), duration), dtype=numpy.float32) data[local_x, over_y[idx]] = over_data[idx] maxlag[i, i + 1:] = N_t - numpy.argmax(data, 1) maxlag[i + 1:, i] = -maxlag[i, i + 1:] maxoverlap[i, i + 1:] = numpy.max(data, 1) maxoverlap[i + 1:, i] = maxoverlap[i, i + 1:] #Now we need to sync everything across nodes maxlag = gather_array(maxlag, comm, 0, 1, 'int32', compress=blosc_compress) if comm.rank == 0: maxlag = maxlag.reshape(comm.size, N_half, N_half) maxlag = numpy.sum(maxlag, 0) maxoverlap = gather_array(maxoverlap, comm, 0, 1, 'float32', compress=blosc_compress) if comm.rank == 0: maxoverlap = maxoverlap.reshape(comm.size, N_half, N_half) maxoverlap = numpy.sum(maxoverlap, 0) if comm.rank == 0: myfile2 = h5py.File(file_out_suff + '.templates%s.hdf5' % extension, 'r+', libver='earliest') for key in ['maxoverlap', 'maxlag', 'version']: if key in myfile2.keys(): myfile2.pop(key) myfile2.create_dataset('version', data=numpy.array( circus.__version__.split('.'), dtype=numpy.int32)) if hdf5_compress: myfile2.create_dataset('maxlag', data=maxlag, compression='gzip') myfile2.create_dataset('maxoverlap', data=maxoverlap, compression='gzip') else: myfile2.create_dataset('maxlag', data=maxlag) myfile2.create_dataset('maxoverlap', data=maxoverlap) myfile2.close()