MPI_Type_create_struct(3)
π 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 arraysarray_of_types,array_of_displacements, andarray_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 uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call. commit your types, bestie!! π€MPI_ERR_OTHERβ other error; useMPI_Error_stringto 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
- nixos 26.05: mpich 5.0.1
- ubuntu stonking: mpich-doc 5.0.1-9 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms