-
Hi there, I would really like to know how to fix or work around the problem I encountered when running a simple code snipper from the docs in a jupyter notebook. from mpi4py import MPI
from mpi4py.futures import MPICommExecutor
with MPICommExecutor(MPI.COMM_WORLD, root=0) as executor:
if executor is not None:
future = executor.submit(abs, -42)
assert future.result() == 42
answer = set(executor.map(abs, [-42, 42]))
assert answer == {42} When I run this code with MPI4PY_FUTURES_MAX_WORKERS=8 mpiexec -n 1 jupyter notebook in a jupyter notebook, I get the error Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 20 replies
-
I see you are setting Using mpi4py under Jupyter is a bit tricky, mostly because MPI implementations sometimes do not support spawning new processes (the 8 workers you want) if the parent process (the kernel) was not executed via Alternatively, you may setup Jupyter to start a cluster using the MPI engine. This cluster needs just one process (the parent), then |
Beta Was this translation helpful? Give feedback.
-
Oh, now I see the difference between from mpi4py import MPI
from mpi4py.futures import MPIPoolExecutor
if __name__ == "__main__":
with MPIPoolExecutor() as executor:
if executor is not None:
future = executor.submit(abs, -42)
assert future.result() == 42
answer = set(executor.map(abs, [-42, 42]))
assert answer == {42} Why doesn't the use of mpiexec mean Jupyter will start the kernel process with mpiexec? Regarding the set up of jupyter to start a cluster using the MPI engine, I will try to find the docs and go through it. Meanwhile, could you please tag some more people who may be aware of this problem and of its resolving? |
Beta Was this translation helpful? Give feedback.
-
If I understand things correctly, the kernel runs in a separate process created at some point, and I don't think that process is under mpiexec control.
I don't really know. Maybe @leofang can think of someone? PS: What MPI implementation are you using on Linux and Windows? |
Beta Was this translation helpful? Give feedback.
-
IIUC you can refer to these resources (disclaimer: I am on my cell and I didn't try)
I think the key is to ensure whenever Jupyter launches a kernel, it's launched under mpiexec. Then the kernel can spawn new processes as long as your MPI backend supports it.
IIRC @minrk is the expert? 🙂 |
Beta Was this translation helpful? Give feedback.
-
That might be the case because I see three new processes (mpiexec, hydra_pmi_proxy, jupyter-noteboo) in top on Linux and two new processes (mpiexec.exe, jupyter.exe, but there is no hydra_pmi_proxy.exe) in tasklist on Windows when I run. mpiexec -n 1 jupyter notebook
Windows mpi 1.0 msmpi conda-forge
mpi4py 3.1.4 py38h73c715a_0 conda-forge
msmpi 10.1.1 h3502643_7 conda-forge Linux mpi 1.0 mpich conda-forge
mpi4py 3.1.4 py38h97ac3a3_0 conda-forge
mpich 4.0.3 h846660c_100 conda-forge |
Beta Was this translation helpful? Give feedback.
-
I will go through these resources. They probably explain how to configure jupyter in order for it to run a kernel under mpiexec.
I would be really appreciate any help 🙂. |
Beta Was this translation helpful? Give feedback.
-
Oh, I see... you are using MPICH. That explains why your kernel process dies. As the kernel process is not executed with @hzhou This is precisely the use case I've been so insistent in the past about getting singleton init + spawn working seamlessly. Thanks again for your prompt action on fixing this long standing issue. |
Beta Was this translation helpful? Give feedback.
-
To start a kernel process with mpiexec, you'll want to modify You may also want to copy the |
Beta Was this translation helpful? Give feedback.
To start a kernel process with mpiexec, you'll want to modify
kernel.json
and addmpiexec
to the command launched (argv
). You can locate the kernelspec directory withjupyter kernelspec list
, but it will generally be at$PREFIX/share/jupyter/kernels/python3/kernel.json
. You can change the command to be a more customizable launch script, rather than launching ipykernel directly, if you want to be able to e.g. try to detect whether mpiexec should be invoked or not.You may also want to copy the
python3
kernel to a new directory, e.g.mpi
(this will create an 'mpi' kernel in your kernel list), if y…