python script running with mpirun not stopping if

2019-09-01 13:33发布

问题:

I have a python script with a set of operations done in parallel, with the library mpi4py. At the end of the operations the processor with rank 0 executes an assert test. If the assert fails, the process should stop and the program terminate. However, the program doesn't exit and this I guess is because the other processors are holding. How to make the program ending the execution if the assert fails? I run things with a command like:

mpirun -np 10 python myscript.py 

and then I have a line in the code like:

if rank ==0:
    assert mytest()==0

回答1:

Instead of assert, you should abort.

https://planet.scipy.org/docs/apiref/mpi4py.MPI.Comm-class.html#Abort

if rank == 0:
    if mytest() === 0:
        comm.Abort()