Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def AllGatherv_unknown_shape(data, comm, rank, n_threads, mpi_dtype, axis=1):
- """
- Use MPI to compute shape of result array by asking every thread for their chunk's shape,
- then perform the AllGatherv operation (concatenating along the given axis) and return the result.
- """
- if axis != 1:
- data = np.swapaxes(data, axis, 1)
- # Require row-major order for concatenation along axis 0
- data = np.require(data, requirements='C')
- dim_1_len = data.shape[1]
- # Gather size of each chunk
- sizes = comm.allgather(data.size)
- offsets = np.zeros(len(sizes), dtype=np.int)
- offsets[1:] = np.cumsum(sizes)[:-1]
- comm.Barrier()
- # Create big array
- tot_size = sum(sizes)
- full_shape = tot_size/dim_1_len, dim_1_len
- all_data = np.zeros(shape=full_shape, dtype=data.dtype, order='C')
- # Perform AllGatherv
- comm.Allgatherv(data, [all_data, sizes, offsets, mpi_dtype])
- if axis != 1:
- all_data = np.swapaxes(all_data, axis, 1)
- return all_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement