MPI_Bsend(3)
π MPI_Bsend β basic send with user-provided buffering π
okay bestie, welcome to the MPI manual page for MPI_Bsend, and yes we are reading the MPI manual together like it's a group chat, because honestly? it kind of is. this one is the send call where you bring the buffer. no cap. π«Ά
β¨ SYNOPSIS β¨
int MPI_Bsend(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm)
int MPI_Bsend_c(const void *buf, MPI_Count count, MPI_Datatype datatype,
int dest, int tag, MPI_Comm comm)
πΈ INPUT PARAMETERS πΈ
bufβ the initial address of the send buffer (it's a choice, so like, whatever you want it to be π )countβ how many elements are living in the send buffer (a non-negative integer, so pls no negatives)datatypeβ the datatype of each element in the send buffer (a handle)destβ the rank of the destination (an integer, the lucky recipient β¨)tagβ the message tag (an integer)commβ the communicator (a handle)
π NOTES π
so this send is literally just a convenience function. it lets you yeet messages out into the world without worrying about where they're buffered β because you, the user, already had to hand over buffer space with MPI_Buffer_attach. that's the whole deal. π
when you're deciding how much buffer space to allocate, remember this: the buffer space is not available for reuse by subsequent MPI_Bsends unless you are certain that the message has been received. like, actually received. not just "it should have been received by now, probably, i think." for example, this code does not allocate enough buffer space:
MPI_Buffer_attach(b, n*sizeof(double) + MPI_BSEND_OVERHEAD);
for (i=0; i<m; i++) {
MPI_Bsend(buf, n, MPI_DOUBLE, ...);
}
because it only provides enough buffer space for a single send, and the loop may start a second MPI_Bsend before the first one is done making use of the buffer. the way that one single buffer is being fought over by a whole loop... it's giving chaos π
in C, you can force the messages to be delivered by doing this:
MPI_Buffer_detach(&b, &n);
MPI_Buffer_attach(b, n);
(MPI_Buffer_detach will not complete until all buffered messages are delivered. so it's basically the "okay everyone come home" call. π )
π§ THREAD AND INTERRUPT SAFETY π§
this routine is thread-safe. which means you can safely use it from multiple threads without needing any user-provided thread locks. slay. π
however β and this is the important part β the routine is not interrupt safe. typically this is because of memory allocation routines like malloc, or other non-MPICH runtime routines, that are themselves not interrupt-safe. so keep that in mind, okay?
π NOTES FOR FORTRAN π
all MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) get an extra argument called ierr tacked onto the end of the argument list. ierr is an integer and it means exactly the same thing as the return value of the routine in C. and in Fortran, MPI routines are subroutines, so you invoke them with the call statement. periodt.
all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran.
π ERRORS π
all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value β C routines as the value of the function, and Fortran routines in the last argument. before that value is returned, the current MPI error handler is called. by default, this error handler aborts the MPI job. π³
the error handler can be changed with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). the MPI-1 routine MPI_Errhandler_set may be used but its use is deprecated. the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned instead. note that MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. π«Ά
MPI_SUCCESSβ no error; the MPI routine completed successfully. iconic.MPI_ERR_BUFFERβ invalid buffer pointer. usually this is a null buffer where a null buffer is not valid.MPI_ERR_COMMβ invalid communicator. a 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.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 the attributeMPI_TAG_UB.MPI_ERR_TYPEβ invalid datatype argument. additionally, this error can occur if an uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call.MPI_ERR_OTHERβ other error; useMPI_Error_stringto get more information about this error code.
π¦ SEE ALSO π¦
MPI_Buffer_attachMPI_IbsendMPI_Bsend_init
and that's the whole page, bestie!! this was the MPI_Bsend(3) page from the MPI manual, dated 4/10/2026, and it's signed off the same way it came in: MPI_Bsend(3). go forth and buffer responsibly. mwah. πβ¨π
π¦ 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