MPI_Recv(3)
π NAME
MPI_Recv β the blocking receive for a message, aka the moment your program sits there like "bestie I am NOT moving until that message shows up" π
This one lives in section 3 of the MPI manual (that's the (3) on the tin, iykyk).
β¨ SYNOPSIS β¨
int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag,
MPI_Comm comm, MPI_Status *status)
int MPI_Recv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status *status)
Yes there are two of them and yes the second one is just the first one with a glow-up on count. We love a range. π¦
π₯ INPUT PARAMETERS π₯
Things you gotta hand over when you call her:
countβ how many elements fit in your receive buffer. Gotta be a non-negative integer, no skips. (It's the max length, more on that down in NOTES π)datatypeβ the datatype of each element in the receive buffer (it's a handle).sourceβ the rank of whoever's sending, orMPI_ANY_SOURCE(an integer).tagβ the message tag, orMPI_ANY_TAG(an integer).commβ the communicator (a handle).
π€ OUTPUT PARAMETERS π€
Things she hands back to you:
bufβ the initial address of the receive buffer (a choice).statusβ the status object (aStatus).
π NOTES π
Okay so here's the tea: that count argument is the maximum length of a message. It is not a promise about how much actually shows up. If you wanna know the actual length of the message you got? That's a whole separate quest β go ask MPI_Get_count. π
π§΅ THREAD AND INTERRUPT SAFETY π§΅
This routine is thread-safe. Translation: multiple threads can use it at the same time and nobody needs to bring their own thread locks. It just works. Slay.
BUT. She is not interrupt safe. No interrupt-safe energy here, periodt. Usually this is because of memory allocation routines like malloc, or other non-MPICH runtime routines, that are themselves not interrupt-safe. So likeβ¦ don't interrupt her mid-glow-up, fr fr. π
π° NOTES FOR FORTRAN π°
Every MPI routine in Fortran β except for MPI_WTIME and MPI_WTICK, those two are the rebels β has one extra argument tacked onto the end of the argument list: ierr. It's an integer, and it means the exact same thing as the return value of the routine does in C.
Also, in Fortran, MPI routines are subroutines, and you invoke them with the call statement. Iconic and traditional.
And every MPI object (like MPI_Datatype, MPI_Comm) is of type INTEGER in Fortran. Every single one. That's just the lore. π
π ERRORS π
Every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β C routines as the value of the function, Fortran routines in that last argument we just talked about.
Before that value comes back to you, the current MPI error handler gets called. And by default? That error handler aborts the MPI job. Not a vibe check, an actual abort. π³
You can change the error handler with:
MPI_Comm_set_errhandlerβ for communicatorsMPI_File_set_errhandlerβ for filesMPI_Win_set_errhandlerβ for RMA windows
The MPI-1 routine MPI_Errhandler_set may be used too, but heads up: its use is deprecated. Don't be the one still using it in 2026 bestie please.
There's also the predefined error handler MPI_ERRORS_RETURN, which you can use to make error values actually get returned to you instead of everything going up in flames.
β οΈ And note β MPI does not guarantee that an MPI program can continue past an error. However, MPI implementations will attempt to continue whenever possible. So like, it might be fine. It might not. Roll the dice. π²
Here's the full squad of error codes:
MPI_SUCCESSβ No error; MPI routine completed successfully. We love a clean run. β¨MPI_ERR_ARGβ Invalid argument. Some argument is invalid and is not identified by a specific error class (e.g.,MPI_ERR_RANK).MPI_ERR_BUFFERβ Invalid buffer pointer. Usually a null buffer where one is not valid. Sir. Please. A null buffer? Here?MPI_ERR_COMMβ Invalid communicator. A super common oopsie is using a null communicator in a call (it's not even allowed inMPI_Comm_rank).MPI_ERR_COUNTβ Invalid count argument. Count arguments must be non-negative; a count of zero is often valid though, so zero isn't always the problem. πMPI_ERR_RANKβ Invalid source or destination rank. Ranks must be between zero and the size of the communicator minus one. But ranks in a receive (MPI_Recv,MPI_Irecv,MPI_Sendrecv, etc.) may also beMPI_ANY_SOURCE.MPI_ERR_TAGβ Invalid tag argument. Tags must be non-negative; tags in a receive (MPI_Recv,MPI_Irecv,MPI_Sendrecv, etc.) may also beMPI_ANY_TAG. The largest tag value is available through the the attributeMPI_TAG_UB. (yes, "the the" β she's a little quirky, we keep her as she is π«Ά)MPI_ERR_TYPEβ Invalid datatype argument. Also, this one can pop up if an uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call. Commit before you transmit, bestie.MPI_ERR_OTHERβ Other error; useMPI_Error_stringto get more information about this error code. The catch-all bin. π
and that's the whole page, no cap π
This was MPI documentation, dated 4/10/2026, from the MPI source β MPI_Recv(3), section 3, out. Go receive something iconic. πππ¦
π¦ where this page comes from
- nixos 26.05: mpich 5.0.1
- ubuntu stonking: mpich-doc 5.0.1-9 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms