python script running with mpirun not stopping if assert on processor 0 fails

回眸只為那壹抹淺笑 提交于 2019-12-12 03:17:35

问题


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()


来源:https://stackoverflow.com/questions/33120286/python-script-running-with-mpirun-not-stopping-if-assert-on-processor-0-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!