MPI job hangs: how to find deadlocks and network problems
Updated · Scientifically reviewed by Dinkar Mishra, PhD on
Short answer
An MPI job hangs either because ranks are waiting for each other (a deadlock: unmatched sends and receives, a collective that not every rank calls, or a rank that crashed silently) or because messages cannot travel (a firewall, the wrong network interface, or interconnect configuration). Find out where each rank is stuck by attaching a debugger or py-spy to the processes, then fix the communication pattern or the network settings.
Who this is for
Developers and users of MPI simulation codes whose jobs stop making progress, freeze at start-up, or hang at scale.
Software
Open MPI / MPICH / Intel MPI anygdb / py-spy any recent
Symptoms
- The job stays
RUNNINGbut stops writing output; the step counter freezes. - It hangs right after start-up, before any computation.
- It works on one node or few ranks and hangs at larger scale.
- All processes use 100% CPU while making no progress. MPI busy-polls while waiting.
Diagnosis
1. Where is each rank stuck? Log in to a compute node running the job (on Slurm: srun --jobid=812345 --overlap --pty bash, if your site allows), find the processes and dump their stacks:
pgrep -u "$USER" -f simulation # PIDs of your ranks on this node
gdb -p 12345 -batch -ex "thread apply all bt" # C, C++, Fortran codes
py-spy dump --pid 12345 # Python (mpi4py) codes
Compare stacks across ranks. A classic deadlock shows some ranks in MPI_Recv or MPI_Wait and others in a different call, for example MPI_Allreduce, or ranks that have exited.
2. Classify the hang.
| Pattern | Likely cause |
|---|---|
Ranks stuck in MPI_Send and MPI_Recv waiting for each other | Send/receive ordering deadlock |
Some ranks in a collective (MPI_Barrier, MPI_Allreduce), others elsewhere | A collective not called by all ranks, or called in a different order |
| One rank missing (crashed), others waiting | Silent failure of one rank; check its stderr and core files |
Hang during MPI_Init or the first communication | Network: firewall, wrong interface, hostname resolution |
| Hang only at large rank counts | Resource limits, interconnect configuration, or a scaling bug |
3. Test the network separately. Run the hello-world from our MPI installation guide across the same nodes. If even that hangs, the problem is the environment, not your code.
Fixes
Ordering deadlocks. Replace paired blocking calls with MPI_Sendrecv, or with non-blocking MPI_Isend/MPI_Irecv followed by MPI_Waitall:
MPI_Request req[2];
MPI_Irecv(recvbuf, n, MPI_DOUBLE, left, 0, MPI_COMM_WORLD, &req[0]);
MPI_Isend(sendbuf, n, MPI_DOUBLE, right, 0, MPI_COMM_WORLD, &req[1]);
MPI_Waitall(2, req, MPI_STATUSES_IGNORE);
Mismatched collectives. Every rank in a communicator must call the same collectives in the same order. Look for collectives inside if (rank == 0) blocks or inside loops whose iteration counts differ between ranks.
Wrong network interface (Open MPI over TCP). Restrict MPI to the cluster network:
mpirun --mca btl_tcp_if_include eth1 --mca oob_tcp_if_include eth1 -np 64 ./simulation
Use the interface name from ip addr that connects the compute nodes.
Firewalls. MPI uses many dynamic ports between nodes. Trust the internal cluster network in the firewall.
InfiniBand and RDMA. Check that ports are active (ibstat) and that the locked-memory limit is unlimited inside jobs (ulimit -l). Use the site’s MPI module, which is built with the correct UCX or verbs support.
When to get help
Contact your HPC centre if simple MPI tests hang across nodes, or if hangs correlate with specific nodes. For code-level deadlocks in large simulation codes, a review of the communication pattern is usually fastest. We provide this as part of our research software and HPC services.
Assumptions and limitations
- Interface options shown are for Open MPI’s TCP transport. MPICH, Intel MPI and UCX-based transports use different environment variables, so consult their documentation.
- Attaching debuggers to compute nodes may be restricted by site policy.
- Eager/rendezvous thresholds vary between implementations and settings, which is why buffering-dependent code can behave differently on different systems.
Frequently asked questions
Why does my code work with small messages but hang with large ones?+
Many MPI implementations send small messages eagerly (buffered), but large messages use a rendezvous protocol that waits for the matching receive. Code where two ranks both call blocking MPI_Send before MPI_Recv works for small data and deadlocks for large data. Use MPI_Sendrecv or non-blocking calls.
How do I test whether my code relies on buffering?+
Temporarily replace MPI_Send with MPI_Ssend (synchronous send), which never buffers. If the program now hangs, it contains an ordering bug that will eventually bite at scale.
The job hangs only on some nodes. What should I check?+
Compare those nodes: interconnect status (ibstat for InfiniBand), firmware and driver versions, locked-memory limits (ulimit -l), and whether the node is healthy. Ask administrators to drain a node that misbehaves repeatedly.
Can MPI time out instead of hanging forever?+
Set a realistic Slurm --time so a hung job does not burn allocation. In your own code, add progress logging per step; some libraries and tools offer watchdogs. A hang that consumes CPU at 100% is usually a busy-wait inside MPI progress, not useful work.
References
- MPI Standard: point-to-point communication semantics · MPI Forum
- Open MPI documentation: networking and tuning · Open MPI project
- py-spy: sampling profiler for Python · py-spy project
- Debugging with GDB: attaching to a running process · GNU
Still stuck?
Send us the error output and your job script. A computational scientist will diagnose it, usually within a day.
Services listed on this page are available today. Products marked “early access” or “in development” on our platform page are not yet generally available.
Spotted an error or an outdated command? Tell us. We correct verified issues promptly.