MPI_Pack_external(3)

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

✨ MPI_Pack_external ✨

okay bestie, welcome to the MPI_Pack_external page from the MPI manual set πŸ’– this is the one that takes your cute little datatype and squishes it into contiguous memory using the external32 format. iykyk.


🌸 NAME 🌸

MPI_Pack_external β€” packs a datatype into contiguous memory, using the external32 format 🫢


πŸŽ€ SYNOPSIS πŸŽ€

int MPI_Pack_external(const char *datarep, const void *inbuf, int incount,
MPI_Datatype datatype, void *outbuf, MPI_Aint outsize,
MPI_Aint *position)

int MPI_Pack_external_c(const char *datarep, const void *inbuf,
MPI_Count incount, MPI_Datatype datatype, void *outbuf,
MPI_Count outsize, MPI_Count *position)

two whole flavors, no cap πŸ’…


πŸ’– INPUT PARAMETERS πŸ’–

  • datarep β€” the data representation, and it's a string bestie ✨
  • inbuf β€” where the input buffer starts (a choice)
  • incount β€” how many input data items you're bringing (an integer)
  • datatype β€” the datatype of each one of those input data items (a handle)
  • outsize β€” the size of the output buffer, measured in bytes (an integer)

πŸ¦‹ INPUT/OUTPUT PARAMETERS πŸ¦‹

  • position β€” the current position in the buffer, in bytes (an integer). it goes in, and it comes back out, main character energy fr fr πŸ‘‘

πŸ“ OUTPUT PARAMETERS πŸ“

  • outbuf β€” where the output buffer starts (a choice)

πŸ”₯ THREAD AND INTERRUPT SAFETY πŸ”₯

okay so the good news: this routine is thread-safe. that means multiple threads can use it safely with zero user-provided thread locks, no babysitting required 🫢

the less good news: it 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 like… interrupt at your own risk πŸ’€


🌈 NOTES FOR FORTRAN 🌈

every MPI routine in Fortran (except MPI_WTIME and MPI_WTICK) has one extra argument at the end called ierr. ierr is 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 call statement, periodt ✨

also, all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. iconic honestly πŸ‘‘


😭 ERRORS 😭

every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β€” C routines as the value of the function, and Fortran routines in that last argument. before the value gets returned, the current MPI error handler gets called. by default, this error handler aborts the MPI job 😳 so yeah, dramatic.

you can swap the error handler 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 β€” so like, don't πŸ‘€

the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. 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, we love to see it πŸ’–
  • 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_COUNT β€” invalid count argument. count arguments must be non-negative; a count of zero is often valid.
  • 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. commit your types bestie 😀
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code.

lowkey reminder: don't use an uncommitted MPI_Datatype in a communication call. that's a MPI_ERR_TYPE waiting to happen 🫣

and that's the whole page bb!! this was version MPI_Pack_external(3) from the MPI manual, dated 4/10/2026. slay, go pack something πŸ’…βœ¨

πŸ“¦ where this page comes from