-
I start 4 processes, main process 0% usage but I see 100% CPU usage on the other processes when waiting for a message: mpirun -n 4 --allow-run-as-root python mpi_test.py from mpi4py import MPI
import time
import os
def mpi_comm():
return MPI.COMM_WORLD
if __name__ == "__main__":
if os.environ["OMPI_COMM_WORLD_NODE_RANK"] == "0":
time.sleep(10)
mpi_comm().isend(["hello"], dest=1)
mpi_comm().isend(["hello"], dest=2)
mpi_comm().isend(["hello"], dest=3)
else:
req = mpi_comm().irecv(source=0)
data = req.wait()
print(data) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
If you do a quick Google search for let say "MPI CPU usage 100%", you may see dozens of very similar reports. This is the behavior of most MPI implementations: they spin the CPU busy-waiting for the arrival of new messages. This behavior has nothing to do with mpi4py, nor mpi4py has a way to directly act on it. You should read the documentation of your backend MPI implementation or ask its support/development team for ways to alleviate the issue, if any. Alternatively, you can change your code and do things slightly different. Instead of a blocking |
Beta Was this translation helpful? Give feedback.
-
Turns out one can also set mpirun --mca mpi_yield_when_idle 1 -n 4 --allow-run-as-root python mpi_test.py |
Beta Was this translation helpful? Give feedback.
Turns out one can also set
mpi_yield_when_idle
to move to degraded busy wait.without mpi_yield:
with mpi_yield: