如果在处理器0上的断言失败,使用mpirun运行的python脚本不会停止 [英] python script running with mpirun not stopping if assert on processor 0 fails

查看:135
本文介绍了如果在处理器0上的断言失败,使用mpirun运行的python脚本不会停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆