我有一个 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()