Why does importing MPI from mpi4py break subprocess calls to mpiexec?

292 Views Asked by At

If I initiate a subprocess call to mpiexec within a python script in which MPI is imported, then the call fails. For example, when calling python test.py, where test.py has the following code

import subprocess

if __name__ == "__main__":
    subprocess.check_call(["mpiexec","-n","2", "echo", "hello world!"])

the output is

hello world!
hello world!

But when test.py is

import subprocess
from mpi4py import MPI
from mpi4py.futures import MPICommExecutor


if __name__ == "__main__":
    subprocess.check_call(["mpiexec","-n","2", "echo", "hello world!"])

the output is

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    subprocess.check_call(["mpiexec","-n","2", "echo", "hello world!"])
  File "anaconda3/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['mpiexec', '-n', '2', 'echo', 'hello world!']' returned non-zero exit status 1.

Can anyone explain why this happens?

0

There are 0 best solutions below