I'm new to mpi4py, but am trying to gain familiarity with it in order to soon parallelize some computational physics code. I have the following short script in order to test it.
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
N = 8
if rank == 0: # main node
P = np.empty(shape = (N, 3, 2))
for n in range(0, size):
P[n, :, :] = n
coreP = np.empty(shape = (N//size, 3, 2), dtype = 'double')
comm.Scatter(P, coreP)
comm.barrier()
print("core {0}/{1}, coreP:\n {2}\n".format(rank, size, coreP))
if rank != 0: # satellite node
P = None
coreP = np.empty(shape = (N//size, 3, 2), dtype = 'double')
comm.Scatter(P, coreP) # what does this line do?
comm.barrier()
print("core {0}/{1}, coreP:\n {2}\n".format(rank, size, coreP))
From which I get the expected result:
core 6/8, coreP:
[[[6. 6.]
[6. 6.]
[6. 6.]]]
core 5/8, coreP:
[[[5. 5.]
[5. 5.]
[5. 5.]]]
...
core 3/8, coreP:
[[[3. 3.]
[3. 3.]
[3. 3.]]]
Or some variation with the cores reordered. My question is, what is the point of the comm.Scatter() command within the satellite node routine? What is it sending, and why does my script output all 0s if it is missing? Why don't I need a root = 0 parameter?
I apologize if these are basic questions, and appreciate any clarification in advance. Thank you.