I am trying to scatter an array of size (3,512,512,48,2), with the data type of double precision np.float64
between 3 processes using Scatter()
:
# mpirun -np 3 python3 prog.py
import numpy as np
from mpi4py import MPI
if __name__ == "__main__":
comm = MPI.COMM_WORLD
nproc = comm.Get_size()
rank = comm.Get_rank()
a = None
a_split = np.empty([512,512,48,2],dtype = np.float64)
if rank==0:
a = np.zeros([3,512,512,48,2],dtype = np.float64)
print(a.shape)
comm.Barrier()
print('Scattering')
comm.Scatter([a, MPI.DOUBLE], a_split, root = 0)
However, program gets a deadlock. From what I have found from here
mpi4py scatter and gather with large numpy arrays
and here
Along what axis does mpi4py Scatterv function split a numpy array?
for big arrays I must use Scatterv()
function. So, here is another code using this function:
# mpirun -np 3 python3 prog.py
import numpy as np
from mpi4py import MPI
if __name__ == "__main__":
comm = MPI.COMM_WORLD
nproc = comm.Get_size()
rank = comm.Get_rank()
a = None
a_split = np.empty([512,512,48,2],dtype = np.float64)
size = 512*512*48*2
if rank==0:
a = np.zeros([3,512,512,48,2],dtype = np.float64)
print(a.shape)
comm.Barrier()
print('Scattering')
comm.Scatterv([a,(size,size,size),(0,size,2*size),MPI.DOUBLE],a_split,root =0)
This, however, also leads to the deadlock. I have also tried to send arrays using point-to-point communication with Send()
,Recv()
but this doesn't help. It appears that deadlocking is depends only on the array size - for example, if I change size of the arrays from [512,512,48,2]
to [512,10,48,2]
, the code works.
Can anyone please suggest what I can do in this situation?