In MPI applications, a program may appear "stuck" or hung even if only a single rank has encountered a protocol violation. Which of the following is the primary reason for this behavior? - MPI automatically terminates all ranks if one rank fails
- The library waits for a heartbeat that is only sent by rank 0.
- Other ranks are waiting for a message from the failing rank that will never arrive.
- The network hardware locks up when it detects a logic error.
Answer: (3) Other ranks are waiting for a message from the failing rank that will never arrive.Because MPI communication is often blocking, if one rank exits or hits a different code path, the ranks expecting to communicate with it will sit idle indefinitely.
A common deadlock pattern occurs when a set of ranks all call blocking sends followed by blocking receives. Under what specific condition might this code actually succeed instead of hanging?
Answer: It only works if message buffering happens to save you.If the MPI implementation has enough internal buffer space to store the outgoing message without waiting for the receiver to “post” a matching receive, the send will complete and the program will move on. If the message is too large for the buffer, it deadlocks.
Fill-in-the-blank: A collective mismatch often looks like the program is stuck inside a routine like MPI_Bcast or MPI_Reduce, but the actual bug is usually a _________ earlier in the code.
Answer: Control flow divergence.The hang happens because different ranks took different logical paths (e.g., an
if/elseblock) and are now trying to execute different collective operations that don’t match up.
Code Analysis: Consider the following snippet. if (rank % 2 == 0) {
MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
} else {
MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
}
What is the likely outcome when run on 4 ranks?
if (rank % 2 == 0) {
MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
} else {
MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
}Answer: The program will hang/deadlock.This is a classic collective mismatch. Even though all ranks call the same two functions, they call them in a different order. MPI collectives are coordinated protocols; if rank 0 enters a “broadcast door” and rank 1 enters a “reduce door,” they cannot synchronize.