MPI_SIZEOF(3)

🌸 NAME 🌸

MPI_Sizeof β€” it hands you the size, in bytes, of whatever type you pass it. that's it. that's the whole job. πŸ’–

(oh and bestie, this one lives in the Open MPI manual, section 3. yes we're fancy.)


✨ SYNTAX ✨

πŸŽ€ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_SIZEOF(X, SIZE, IERROR)
<type>       X
INTEGER      SIZE, IERROR

πŸ¦‹ Fortran 2008 Syntax

USE mpi_f08
MPI_Sizeof(x, size, ierror)
     TYPE(*), DIMENSION(..) :: x
     INTEGER, INTENT(OUT) :: size
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ’œ INPUT PARAMETER

  • X β€” a Fortran variable of numeric intrinsic type (choice). it's giving "pick your fighter" energy, you literally choose which numeric type you're asking about. 🌈

🫢 OUTPUT PARAMETERS

  • SIZE β€” the size of the machine representation of that type (integer). like the byte count. the receipts. 🧾
  • ierror β€” error status (integer).

πŸ”₯ DESCRIPTION πŸ”₯

MPI_Sizeof returns the size, in bytes, of the machine representation of the variable you gave it. periodt. πŸ’…

It's a generic Fortran type and it has a Fortran binding only β€” so don't come looking for it anywhere else, bestie, it's not there. πŸ™ˆ

It's basically the same vibe as the sizeof builtin in C. iconic behavior honestly.

BUT β€” and this is the plot twist, pay attention 😭 β€” if you hand it an array argument, it returns the size of the base element, not the size of the whole array. so like, the individual thing, not the whole squad. don't get got by that one.


🌟 NOTES 🌟

This function is not available in C because it is not necessary. yeah. C said "I already have sizeof, I'm good," and honestly? valid. πŸ‘‘


πŸ’€ ERRORS πŸ’€

okay so this part is long but it's important, stay with me. 🫢

Almost all MPI routines return an error value: C routines return it as the return result of the function, and Fortran routines return it in the last argument.

Before that error value gets returned, the current MPI error handler associated with the communication object (think: communicator, window, file) gets 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. And when MPI_COMM_SELF is not initialized β€” that means before MPI_Init / MPI_Init_thread, after MPI_Finalize, or when you're using the Sessions Model exclusively β€” the error raises the initial error handler.

You can change that initial error handler by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model, or via the mpi_initial_errhandler CLI argument to mpiexec, or via an 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 ships three predefined error handlers you can use:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. yes, everyone. the whole group chat. 😭
  • MPI_ERRORS_ABORT β€” an error handler that can be invoked on a communicator, window, file, or session. When it's called on a communicator, it acts as if MPI_Abort was called on that communicator. If it's called on a window or a file, it acts as if MPI_Abort was called on a communicator containing the group of processes in the corresponding window or file. If it's called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application. polite. considerate. we love her. πŸ’–

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 promises, bestie. 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. iykyk πŸ“š


2003-2026, The Open MPI Community


and that's the whole page, bestie β€” Open MPI's MPI_SIZEOF(3), dated Sep 10, 2026. go forth and byte-count responsibly, you absolute icon. πŸ¦‹πŸ’…βœ¨

πŸ“¦ where this page comes from