When I run the code below using mpiexec -n 5 python mpiTest.py
, I expect every process to print its message immediately, then sleep for the specified amount of time. Instead, it executes as if I put the print
command AFTER the sleep
command. Why does this happen and how can I get it to behave as expected?
Adding a MPI.COMM_WORLD.Barrier()
between the print
and sleep
commands does NOT help.
I'm using MS-MPI on win10.
from mpi4py import MPI
import random
import time
def delayed():
random.seed()
sek = random.randint( 1, 5 )
print( "Delaying for ", sek, " seconds." )
time.sleep( sek )
return
delayed()