MPI_Irecv(3)
π NAME π
okay bestie, gather round β this is MPI_Irecv from the MPI manual (section 3, yes ma'am), and it begins a nonblocking receive. that's the whole vibe. you're not waiting for the message like some kind of peasant, you're starting the receive and getting a cute little handle back so you can go do literally anything else. main character energy fr fr. π¦
π SYNOPSIS π
int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Irecv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Request *request)
two flavors, both iconic: the regular one and the _c one that takes an MPI_Count instead of an int for count. pick your fighter. π
β¨ INPUT PARAMETERS β¨
these are the things you hand over. the lore. the tea. π
countβ how many elements are chillin' in your receive buffer, as a non-negative integer. no negative counts bestie, we don't do that here.datatypeβ the datatype of each element in that receive buffer (a handle).sourceβ the rank of whoever's sending to you, orMPI_ANY_SOURCEif you're in your "I'll take whoever shows up" era. (integer)tagβ the message tag, orMPI_ANY_TAGif you're not being picky. (integer)commβ the communicator (handle). your lil friend group.
πΈ OUTPUT PARAMETERS πΈ
stuff you get back, no cap:
bufβ the initial address of your receive buffer (a choice).requestβ the communication request (handle). hold onto this, you'll need it later for things likeMPI_WaitandMPI_Test. it's literally the receipt. π§Ύ
π§΅ THREAD AND INTERRUPT SAFETY π§΅
okay so good news first: this routine is thread-safe. that means multiple threads can safely use it without you having to build your own thread locks or anything. queen shit. no user-provided locks required. periodt. π
but β and there's always a but β it is not interrupt safe. the reason, typically, is that it uses memory allocation routines like malloc or other non-MPICH runtime routines, and those themselves are not interrupt-safe. so like, know that going in. π
π NOTES FOR FORTRAN π
for my Fortran girlies:
- all MPI routines in Fortran (except for
MPI_WTIMEandMPI_WTICK) get an extra argument calledierrtacked onto the end of the argument list.ierris an integer and it means the exact same thing as the return value of the routine in C. - in Fortran, MPI routines are subroutines, and you invoke them with the
callstatement. yes, like that. - also, literally all MPI objects (e.g.,
MPI_Datatype,MPI_Comm) are of typeINTEGERin Fortran. that's just how it is.
π ERRORS π
okay so every single MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β in C it's the value of the function, and in Fortran it's the last argument. before that value comes back to you, the current MPI error handler gets called. and by default? that error handler aborts the entire MPI job. dramatic, I know.
you can swap the error handler out with:
MPI_Comm_set_errhandlerβ for communicatorsMPI_File_set_errhandlerβ for filesMPI_Win_set_errhandlerβ for RMA windows
there's also the MPI-1 routine MPI_Errhandler_set, which you may use, but heads up: its use is deprecated. we don't stan it anymore.
if you want error values to actually be returned instead of nuking your job, use the predefined error handler MPI_ERRORS_RETURN. π«Ά
one more important thing: MPI does not guarantee that an MPI program can continue past an error. however, MPI implementations will attempt to continue whenever possible. so like, maybe. fingers crossed. π€
here's the error roster:
MPI_SUCCESSβ no error! the MPI routine completed successfully. we love a clean run. β¨MPI_ERR_ARGβ invalid argument. some argument is invalid and isn't identified by a specific error class (e.g.,MPI_ERR_RANK).MPI_ERR_BUFFERβ invalid buffer pointer. usually that's a null buffer in a spot where null is just not valid.MPI_ERR_COMMβ invalid communicator. a super common oopsie is using a null communicator in a call (which isn't 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 don't panic.MPI_ERR_RANKβ invalid source or destination rank. ranks must be between zero and the size of the communicator minus one; 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 attributeMPI_TAG_UB.MPI_ERR_TYPEβ invalid datatype argument. additionally, this error can happen if an uncommittedMPI_Datatype(seeMPI_Type_commit) gets used in a communication call.MPI_ERR_OTHERβ other error; useMPI_Error_stringto get more info about this error code.
pro tip from me to you: if you seeMPI_ERR_OTHER, go askMPI_Error_stringwhat's going on. it's giving "just talk to me". π
and that's the whole page bestie, you ate that. this was the MPI manual, MPI_Irecv(3), dated 4/10/2026 β go start a nonblocking receive and slay. π
β¨π
π¦ 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