MPI_Bsend(3)

πŸ“¦
version 5.0.1 Β· 5 versions
, in nixos 26.05, ubuntu stonking

πŸ’– 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 in MPI_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 be MPI_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 be MPI_ANY_TAG. the largest tag value is available through the the attribute MPI_TAG_UB.
  • MPI_ERR_TYPE β€” invalid datatype argument. additionally, this error can occur if an uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call.
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code.

πŸ¦‹ SEE ALSO πŸ¦‹

  • MPI_Buffer_attach
  • MPI_Ibsend
  • MPI_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