python 脚本 运行 如果处理器 0 上的断言失败,则 mpirun 不会停止

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

我有一个 python 脚本,其中包含一组并行完成的操作,使用库 mpi4py。 在操作结束时,等级为 0 的处理器执行断言测试。如果断言失败,进程应该停止并且程序终止。但是,程序没有退出,我猜这是因为其他处理器正在等待。如果断言失败,如何让程序结束执行? 我 运行 使用如下命令进行操作:

mpirun -np 10 python myscript.py 

然后我在代码中有一行:

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

您应该中止,而不是断言。

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

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