MPIPoolExecutor导致mpiexec启动超时问题排查求助
问题分析与解答
问题场景
执行命令:
mpiexec -n 1 python scratch.py
其中scratch.py代码如下:
from mpi4py.futures import MPIPoolExecutor def square(i): global initialized try: initialized except NameError: initialized = False if not initialized: print("expensive initialization") import time time.sleep(2) initialized = True return i**2 if __name__ == '__main__': with MPIPoolExecutor(2) as ex: for result in ex.map(square, range(7)): print(result)
命令执行后一直挂起,执行ps aux | grep mpi发现存在进程:
username 16944 44.6 0.0 377280 14476 ? Rl 09:46 0:03 python -R -m mpi4py.futures.server
排查防火墙状态,systemctl status firewalld显示防火墙已关闭:
firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
单独执行python3 -R -m mpi4py.futures.server时出现错误:
Traceback (most recent call last): File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/people/hkaya/.local/lib/python3.8/site-packages/mpi4py/futures/server.py", line 14, in <module> main() File "/home/people/hkaya/.local/lib/python3.8/site-packages/mpi4py/futures/server.py", line 10, in main _lib.server_main() File "/home/people/hkaya/.local/lib/python3.8/site-packages/mpi4py/futures/_lib.py", line 1068, in server_main server_main_service() File "/home/people/hkaya/.local/lib/python3.8/site-packages/mpi4py/futures/_lib.py", line 1057, in server_main_service comm = server_accept(service, info) File "/home/people/hkaya/.local/lib/python3.8/site-packages/mpi4py/futures/_lib.py", line 1006, in server_accept MPI.Publish_name(service, port, info) File "mpi4py/MPI/Comm.pyx", line 2755, in mpi4py.MPI.Publish_name mpi4py.MPI.Exception: MPI_ERR_INTERN: internal error -------------------------------------------------------------------------- MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD Proc: [[32891,0],0] Errorcode: 1
环境信息:
- Python 3.8.0
- MPICH 4.2.0
- 操作系统:Scientific Linux 7.4
- CPU:Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz(4核)
一、python -R -m mpi4py.futures.server的作用
这是mpi4py中MPIPoolExecutor组件的后台服务进程,核心职责包括:
- 接收主进程下发的任务调度请求
- 管理指定数量的工作进程池,分配任务到空闲进程执行
- 收集任务执行结果并回传给主进程
它是主进程和工作进程之间的中间调度层,当代码中初始化MPIPoolExecutor(2)时,主进程会自动启动该服务进程,再由服务进程拉起2个工作进程处理任务。
二、命令挂起的原因
结合错误信息和环境,核心问题在于MPI名字服务的兼容性:
MPI名字服务调用失败
单独运行服务进程时,MPI.Publish_name函数抛出MPI_ERR_INTERN错误,这个函数的作用是将服务进程的端口信息发布到MPI名字服务,让主进程能找到并连接它。该调用失败直接导致服务进程无法完成初始化,陷入等待。环境版本兼容性问题
你的环境是Scientific Linux 7.4(系统库较旧)搭配MPICH 4.2.0(新版本MPI),MPICH 4.x对系统依赖的要求较高,旧系统上的名字服务组件可能无法正常工作,引发内部错误。进程间等待死锁
主进程启动服务进程后,会等待服务进程的就绪信号;而服务进程因为名字服务发布失败,无法向主进程发送就绪信号,最终导致整个任务链挂起,双方互相等待。
三、解决建议
- 降级MPICH版本:切换到MPICH 3.4.x版本,该版本对旧Linux系统的兼容性更好,能避免新特性与旧系统库的冲突。
- 禁用MPI名字服务:执行命令时添加
--disable-name-server参数,强制进程间直接通信,绕开名字服务的问题:mpiexec -n 1 --disable-name-server python scratch.py - 匹配mpi4py版本:确保mpi4py版本与MPICH版本适配,建议使用mpi4py 3.1.x系列,它对Python 3.8和MPICH 3.x/4.x的兼容性更稳定。
内容的提问来源于stack exchange,提问作者Hikmet Emre Kaya
相关产品推荐
相关产品推荐

