MPI_Type_create_struct(3)

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

πŸ’– MPI_Type_create_struct(3) β€” the MPI manual, bestie edition πŸ’–

okay so picture this: you need a datatype that's not just "same thing over and over" (that's for basic girls) but a whole general set of datatypes, displacements, and block sizes. That's this one. It's from the MPI manual and it's giving main character energy fr fr.


✨ NAME ✨

MPI_Type_create_struct β€” create an MPI datatype from a general set of datatypes, displacements, and block sizes


🌸 SYNOPSIS 🌸

int MPI_Type_create_struct(int count, const int array_of_blocklengths[],
const MPI_Aint array_of_displacements[],
const MPI_Datatype array_of_types[],
MPI_Datatype *newtype)
int MPI_Type_create_struct_c(MPI_Count count,
const MPI_Count array_of_blocklengths[],
const MPI_Count array_of_displacements[],
const MPI_Datatype array_of_types[],
MPI_Datatype *newtype)

πŸŽ€ INPUT PARAMETERS πŸŽ€

  • count β€” the number of blocks. and ALSO the number of entries in the arrays array_of_types, array_of_displacements, and array_of_blocklengths. one number, four jobs, she's booked and busy. (non-negative integer)
  • array_of_blocklengths β€” how many elements are in each block. (non-negative integer)
  • array_of_displacements β€” the byte displacement of each block. (integer)
  • array_of_types β€” the types of the elements in each block. (handle)

πŸ¦‹ OUTPUT PARAMETERS πŸ¦‹

  • newtype β€” the new datatype. fresh out the box, your new baby. (handle)

πŸ’… THREAD AND INTERRUPT SAFETY πŸ’…

This routine is thread-safe, periodt. That means multiple threads can use it at the same time and you do NOT need to bring your own thread locks, she handles herself. πŸ’β™€οΈ

BUT. And it's a big but. She is not interrupt safe. Not even a little. Why? Typically because of memory allocation routines like malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. So like, don't be doing interrupt shenanigans, iykyk.

⚠️ not interrupt safe. write that down.

πŸ‘‘ NOTES FOR FORTRAN πŸ‘‘

All MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is an integer and has the same meaning as the return value of the routine in C. In Fortran, MPI routines are subroutines, and they're invoked with the call statement. so iconic of them.

All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. no vibes, just integers. πŸ’œ


😭 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 the value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job (dramatic much? but that's literally what it does).

The error handler may 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 πŸ™ˆ β€” she's outdated, we don't do that anymore.

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.

Now the error codes, the full roster:

  • MPI_SUCCESS β€” no error; MPI routine completed successfully. slay. βœ…
  • 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.

and that's the whole page, you ate that. go build your funky little struct datatype, I believe in you πŸ’–βœ¨πŸ¦‹

this has been the MPI_Type_create_struct(3) manual page, from the MPI docs, dated 4/10/2026 β€” mwah, kisses, now go compile something gorgeous πŸŽ€πŸ’…

πŸ“¦ where this page comes from