无法使用subprocess.Popen启动mpirun

2 投票
1 回答
1369 浏览
提问于 2025-04-18 18:33

我正在按照这里的说明进行操作。

出现的问题是,wait或者communicate会立即返回,而不等mpi进程完成。我是在我的Python应用程序中的一个单独线程里做这个。当我在Python命令行中交互式地执行时,有时似乎能正常工作。也许我需要在Popen之后和wait/communicate之前等一下?

我调用Popen的方式如下:

mpicmd = 'mpirun -n 2 --hostfile hostfile ' + executable + ' ' + mpiArgs
mpirun = subprocess.Popen(mpicmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = mpirun.communicate()

当我从我的程序中运行mpirun时,我得到了:

--------------------------------------------------------------------------
There are no allocated resources for the application 
  rttl
that match the requested mapping:
  hostfile

Verify that you have mapped the allocated resources properly using the 
--host or --hostfile specification.

而当我在同一个目录下交互式地执行时,它是可以工作的。

我还尝试了:

mpirun = subprocess.Popen(['mpirun', '-n', '2', '--hostfile', 'hostfile', 'rttl', '10000'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

结果也是一样。

1 个回答

1

我刚遇到同样的问题。我在写我的主机文件内容到一个文件里,代码是这样的:

myfile = open("hostfile", "w")
myfile.write("localhost")

然后我调用了MPI命令。问题是我忘记加myfile.close()这个命令了……在MPI命令之前加上这个,问题就解决了。

我知道这是一篇旧帖子,但也许会有人遇到同样的问题。

撰写回答