# MPI Deadlock **Deadlock** occurs when process 0 sends to process 1 while process 1 sends to process 0 simultaneously; both block waiting for a receive that never comes. ```c // deadlock: both processes block on MPI_Send waiting for the other to MPI_Recv MPI_Send(buf, N, MPI_DOUBLE, peer, 0, MPI_COMM_WORLD); MPI_Recv(buf, N, MPI_DOUBLE, peer, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); ``` The standard fixes are: use `MPI_Sendrecv`, which handles ordering internally; post a non-blocking `MPI_Isend` first, then `MPI_Recv`, then `MPI_Wait`; or alternate send/receive order by rank so even-rank processes send first and odd-rank processes receive first. Whether `MPI_Send` actually blocks depends on the implementation's internal buffer size, so relying on it to absorb a large message is non-portable and can silently deadlock on a different machine.