MPI_Type_size(3)

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

πŸ’– MPI_Type_size(3) β€” a manual page from the MPI fam πŸ’–

okay bestie, sit down, hydrate, because today we're learning how to ask MPI how many bytes does this datatype actually eat and honestly? it's giving essential. πŸŽ€


✨ NAME ✨

MPI_Type_size β€” returns the number of bytes occupied by entries in the datatype. yes that's the whole job. she's simple, she's iconic, she's booked and busy. πŸ’…


🌸 SYNOPSIS 🌸

int MPI_Type_size(MPI_Datatype datatype, int *size)

int MPI_Type_size_c(MPI_Datatype datatype, MPI_Count *size)

two flavors, same energy fr fr. πŸ¦‹


πŸ’œ INPUT PARAMETERS πŸ’œ

  • datatype β€” the datatype (a handle, bestie, so don't go passing her a random int and expecting magic πŸ™ˆ)

🫢 OUTPUT PARAMETERS 🫢

  • size β€” the datatype size, and it comes back as an integer ✨

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

okay so the good news first: this routine is thread-safe. that means you can safely use it from multiple threads and you do not need to bring your own thread locks β€” no user-provided thread locks required, she handles herself. main character energy, no notes. πŸ‘‘

but β€” and this is the plot twist 😭 β€” the routine is not interrupt safe. the usual culprit is memory allocation routines like malloc or other non-MPICH runtime routines, because those themselves are not interrupt-safe. so like, respect the boundary, okay?


🌈 NOTES FOR FORTRAN 🌈

so Fortran besties, this part is for you 🫢:

  • Every MPI routine in Fortran (except MPI_WTIME and MPI_WTICK) has one extra argument: ierr, tacked on at 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. ✨
  • In Fortran, MPI routines are subroutines, and you invoke them with the call statement. periodt.
  • All MPI objects β€” like MPI_Datatype and MPI_Comm β€” are of type INTEGER in Fortran. yes, all of them. πŸ’…

πŸ’€ ERRORS πŸ’€

lowkey important, highkey dramatic: by default, the error handler aborts the MPI job. so maybe read this part before you YOLO your HPC allocation πŸ™ˆ

All MPI routines (except MPI_Wtime and MPI_Wtick) return an error value β€” C routines return it as the value of the function, and Fortran routines put it in the last argument. Before that value comes back, the current MPI error handler gets called. By default, this error handler aborts the MPI job. 😭

You can swap the error handler out with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). There's also the MPI-1 routine MPI_Errhandler_set, and you may use it, but heads up: its use is deprecated. 🚩

If you'd rather get error values returned instead of getting your job nuked, use the predefined error handler MPI_ERRORS_RETURN. And real talk: MPI does not guarantee that an MPI program can continue past an error β€” however, MPI implementations will attempt to continue whenever possible. so it's giving "we'll try bestie, no promises." 🫠

Here's the error code menu πŸ“:

  • MPI_SUCCESS β€” no error; the MPI routine completed successfully. slay. ✨
  • MPI_ERR_ARG β€” invalid argument. Some argument is invalid and isn't identified by a specific error class (e.g., MPI_ERR_RANK). πŸ’€
  • 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, i'm begging πŸ™
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code. 🧚

and that's the whole page, no cap. go forth and count your bytes, queen πŸ‘‘πŸ¦‹πŸ’–

mwah πŸ’‹ β€” this was MPI_Type_size(3) from the MPI manual, dated 4/10/2026. take care of her, she's iconic.

πŸ“¦ where this page comes from