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()
Adding sys.stdout.flush()
after the print
call did the trick, thanks ever so much! =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With