MPI4py: MPI Communicate Through a Loop Between Processes
I have 2 processes in my program. Where process(0)
is the leader, and process(1)
- the subordinate. There is a common loop for both (which increases from 0 to 4). I am trying to send value ( i
) to process(1)
from process(0)
. But process(1)
doesn't get new values i
from process(0)
.
cw = MPI.COMM_WORLD
rank = cw.Get_rank()
nProcesses = cw.Get_size()
currentTrial = np.zeros(nProcesses-1, dtype='int32')
receivedTrial = np.zeros(1, dtype='int32')
i = 0
while (i < 5):
if (rank == 0):
currentTrial[0] = 0
#print(i)
sendToSlave = cw.Isend(currentTrial[0:1], dest=1)
print(sendToSlave.Test())
i = i+ 1
currentTrial[0] = i
if (rank != 0):
#receive a trial number
receiveFromMaster = cw.Recv(receivedTrial[:], source=0)
print("rank", rank,receivedTrial)
I am currently getting:
True
rank 1 [0]
True
True
True
True
rank 1 [0]
rank 1 [0]
rank 1 [0]
rank 1 [0]
Ideally process(1)
should print[0] [1] [2] [3] [4]
source to share
No one has answered this question yet
Check out similar questions: