MPI_PACK_EXTERNAL_SIZE(3)

πŸ’– NAME πŸ’–

MPI_Pack_external_size β€” bestie, this one calculates the upper bound on how much space you need to write stuff out in a portable format πŸ’…

It lives in the Open MPI manual, and honestly? She's a lil niche but so important. ✨


🌸 SYNTAX 🌸

✨ C Syntax

#include <mpi.h>

int MPI_Pack_external_size(const char *datarep, int incount,
     MPI_Datatype datatype, MPI_Aint *size)

✨ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_PACK_EXTERNAL_SIZE(DATAREP, INCOUNT, DATATYPE, SIZE, IERROR)

     INTEGER         INCOUNT, DATATYPE, IERROR
     INTEGER(KIND=MPI_ADDRESS_KIND) SIZE
     CHARACTER*(*)   DATAREP

✨ Fortran 2008 Syntax

USE mpi_f08
MPI_Pack_external_size(datarep, incount, datatype, size, ierror)
     TYPE(MPI_Datatype), INTENT(IN) :: datatype
     INTEGER, INTENT(IN) :: incount
     CHARACTER(LEN=*), INTENT(IN) :: datarep
     INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(OUT) :: size
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸŽ€ INPUT PARAMETERS πŸŽ€

  • datarep β€” the data representation, and it's a string, okay? πŸ“
  • incount β€” how many input data items you're bringing to the party (integer, natch).
  • datatype β€” the datatype of each one of those input data items (handle energy πŸ‘‘).

πŸ’– OUTPUT PARAMETERS πŸ’–

  • size β€” the upper bound on the size of the packed message, measured in bytes (integer).
  • ierror β€” Fortran only bestie: error status (integer). πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

So MPI_Pack_external_size lets your application find out exactly how much space it's gonna need to pack a message in the portable format that the MPI Forum defined. It hands you back, in size, an upper bound on the increment in position that would occur in a call to MPI_Pack_external with the same values for datarep, incount, and datatype. iykyk πŸ’…

Now the thing is β€” it returns an upper bound, not an exact bound. And that's on purpose, bestie. The exact amount of space needed to pack the message may depend on context and alignment (like, for example, the first message packed in a packing unit might take up more space). So she gives you a safe ceiling instead of a precise number. Periodt. ✨


🌈 NOTES 🌈

The datarep argument is what specifies the data format. And the only valid value in the current version of MPI is "external32". One (1) option. That's it. The argument is there for future extensibility, so like... she's future-proofed, she's just not there yet. πŸ’œ


πŸ’€ ERRORS πŸ’€

Almost all MPI routines return an error value, okay? For C routines it's the return result of the function, and for Fortran routines it's in the last argument. Ngl, keep an eye on it. πŸ‘€

Before that error value gets returned, the current MPI error handler associated with the communication object (think: communicator, window, file) is called. If there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and it will call the associated MPI error handler. When MPI_COMM_SELF is not initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively) the error raises the initial error handler. The initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or the mpi_initial_errhandler CLI argument to mpiexec or info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple. If no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions and the MPI_ERRORS_ABORT error handler is called for all other MPI functions. 😭

Open MPI includes three predefined error handlers that can be used:

  • MPI_ERRORS_ARE_FATAL β€” Causes the program to abort all connected MPI processes. Yeah. She said what she said. πŸ’€
  • MPI_ERRORS_ABORT β€” An error handler that can be invoked on a communicator, window, file, or session. When called on a communicator, it acts as if MPI_Abort was called on that communicator. If called on a window or file, acts as if MPI_Abort was called on a communicator containing the group of processes in the corresponding window or file. If called on a session, aborts only the local process.
  • MPI_ERRORS_RETURN β€” Returns an error code to the application. The chill one. 🫢

MPI applications can also implement their own error handlers by calling:

  • MPI_Comm_create_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_Win_set_errhandler

Note that MPI does not guarantee that an MPI program can continue past an error. Like, no cap, it might just be over. 😭

See the MPI man page for a full list of MPI error codes.

See the Error Handling section of the MPI-3.1 standard for more information.

See also:

  • MPI_Pack_external
  • MPI_Unpack_external

2003-2026, The Open MPI Community β€” bless them, icons only. πŸ’–


That's the whole vibe bestie, hope this helped βœ¨πŸ¦‹ This page came from the Open MPI manual, dated Sep 10, 2026, and you were reading MPI_PACK_EXTERNAL_SIZE(3) the whole time. Slay, go pack something external. πŸ’…πŸŽ€

πŸ“¦ where this page comes from