如果在处理器0上的断言失败,使用mpirun运行的python脚本不会停止 [英] python script running with mpirun not stopping if assert on processor 0 fails
问题描述
我有一个python脚本,带有一组并行执行的操作,以及库mpi4py. 在操作结束时,等级为0的处理器将执行断言测试.如果断言失败,则过程应停止并且程序终止.但是,该程序没有退出,我想这是因为其他处理器正在挂起.如果断言失败,如何使程序结束执行? 我使用以下命令运行内容:
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
然后在代码中有一行:
if rank ==0:
assert mytest()==0
推荐答案
您应该中止而不是断言.
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()
这篇关于如果在处理器0上的断言失败,使用mpirun运行的python脚本不会停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!