MPI4py:MPI通过进程之间的循环进行通信

时间:2014-12-05 03:20:14

标签: python parallel-processing mpi4py

我的程序中有2个进程。其中process(0)是主人,process(1)是奴隶。两者都有一个共同的循环(从0增加到4)。 我正在尝试从iprocess(1)发送值process(0)。但是process(1)无法从i获取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)

这是我得到的输出:

True
rank 1 [0]
True
True
True
True
rank 1 [0]
rank 1 [0]
rank 1 [0]
rank 1 [0]

理想情况下,process(1)应打印[0] [1] [2] [3] [4]

0 个答案:

没有答案
相关问题