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]

+3
python parallel-processing mpi4py


source to share


No one has answered this question yet

Check out similar questions:

170
Permanently print Subprocess output during process
25
How are MPI_Scatter and MPI_Gather used with C?
1
mpi4py: Communication between spawned processes
1
Parallelizing a loop that involves random sampling using mpi4py
1
MPI Asynchoronous Send and Receive not working as expected
1
mpi p2p send receive messages between c and c ++ codes
0
MPI hello world doesn't read processes correctly
0
How to safely switch to another communicator in MPI
0
mpi4py: problem sending messages to slaves via send / recv
0
The program is stuck somewhere



All Articles
Loading...
X
Show
Funny
Dev
Pics