Why the 1st iprobe() returns False?

24 Views Asked by At

I am learning how to use MPI in Python. (Windows 10 + Cygwin + Python 3.9.16 + mpi4py + OpenMPI 4.1.6) I don't understand why iprobe() returns False in the following situation.

I expect in the following script that sleep(5) is executed only once.

import time, datetime
from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

if rank == 0:
    comm.send(rank, 1)
        while True:
            print("DEBUG: 0: Receiving", datetime.datetime.now())
            status = comm.iprobe()
            print("DEBUG:", status, datetime.datetime.now())
            if status:
                break
            time.sleep(5)
        n = comm.recv()
        print(n)
else:
        m = comm.recv()
        comm.send(m, 0)
        print("DEBUG: 1: Sent", datetime.datetime.now())

However, the result was

DEBUG: 1: Sent 2024-02-20 18:43:12.694506
DEBUG: 0: Receiving 2024-02-20 18:43:12.694453
DEBUG: False 2024-02-20 18:43:12.694499
DEBUG: 0: Receiving 2024-02-20 18:43:17.703331
DEBUG: False 2024-02-20 18:43:17.703411
DEBUG: 0: Receiving 2024-02-20 18:43:22.713877
DEBUG: True 2024-02-20 18:43:22.713962
0

iprobe() returned False at 18:43:17 despite that rank 1 have sent a message 5 seconds ago. When I modify the script to repeat iprobe() twice, as

        print("DEBUG: 0: Receiving", datetime.datetime.now())
        status = comm.iprobe()
        status = comm.iprobe()
        print("DEBUG:", status, datetime.datetime.now())

then the results becomes as follows:

DEBUG: 0: Receiving 2024-02-20 18:47:06.379715
DEBUG: False 2024-02-20 18:47:06.379762
DEBUG: 1: Sent 2024-02-20 18:47:06.379768
DEBUG: 0: Receiving 2024-02-20 18:47:11.386850
DEBUG: True 2024-02-20 18:47:11.386937
0

It seems that iprobe() returns False at the first time regardless if there is a message. Why does it happen?

0

There are 0 best solutions below