4

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()
endlesse
  • 141
  • 1
  • 6
  • 3
    You probably need to flush your IO buffer. Try `sys.stdout.flush()` after the `print` call. – eduffy Apr 03 '17 at 23:37

1 Answers1

10

Adding sys.stdout.flush() after the print call did the trick, thanks ever so much! =)

endlesse
  • 141
  • 1
  • 6