MPI_Type_indexed(3)

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

πŸ’– MPI_Type_indexed(3) β€” the MPI manual, but make it make sense πŸ’–

okay bestie, welcome to the MPI manual page for MPI_Type_indexed. yes it's from the MPI manual. yes it's about datatypes. yes you're gonna understand it. let's go ✨


🌸 NAME 🌸

MPI_Type_indexed β€” creates an indexed datatype πŸŽ€


✨ SYNOPSIS ✨

int MPI_Type_indexed(int count, const int array_of_blocklengths[],
const int array_of_displacements[], MPI_Datatype oldtype,
MPI_Datatype *newtype)

int MPI_Type_indexed_c(MPI_Count count, const MPI_Count array_of_blocklengths[],
const MPI_Count array_of_displacements[],
MPI_Datatype oldtype, MPI_Datatype *newtype)

two versions, one vibe. the _c one is the big-count girlie 🫢


πŸ’… INPUT PARAMETERS πŸ’…

  • count β€” the number of blocks, and also the number of entries in array_of_displacements and array_of_blocklengths. it's a non-negative integer, so like, no negativity allowed 🚫
  • array_of_blocklengths β€” how many elements go in each block. non-negative integer, we stay positive ✨
  • array_of_displacements β€” the displacement for each block, measured in multiples of oldtype. integer. (iykyk this one matters, there's a whole Fortran situation below πŸ‘€)
  • oldtype β€” the old datatype (a handle)

πŸ‘‘ OUTPUT PARAMETERS πŸ‘‘

  • newtype β€” the new datatype (a handle). your brand new baby datatype, slay πŸ’–

🧡 THREAD AND INTERRUPT SAFETY 🧡

this routine is thread-safe, meaning multiple threads can use it at the same time and you do not need to bring your own thread locks. no cap. 🫢

however β€” and this is the key part, bestie β€” it is not interrupt safe. typically that's because of memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, thread-safe yes, interrupt-safe no. periodt.


πŸ¦‹ NOTES FOR FORTRAN πŸ¦‹

every MPI routine in Fortran (except MPI_WTIME and MPI_WTICK) has an extra argument ierr at the end of the argument list. ierr is an integer and it means 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.

all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. the array_of_displacements are displacements, and they are based on a zero origin. and a common error is to do something like the following πŸ‘‡

integer a(100)
integer array_of_blocklengths(10), array_of_displacements(10)
do i=1,10
array_of_blocklengths(i)   = 1
10       array_of_displacements(i) = 1 + (i-1)*10
call MPI_TYPE_INDEXED(10,array_of_blocklengths,array_of_displacements,MPI_INTEGER,newtype,ierr)
call MPI_TYPE_COMMIT(newtype,ierr)
call MPI_SEND(a,1,newtype,...)

so the person writing this is expecting it to send "a(1),a(11),..." because the array_of_displacements have values "1,11,...". but nooo 😭 β€” because these are displacements from the beginning of "a", it actually sends "a(1+1),a(1+11),...".

if you want to consider the displacements as array_of_displacements into a Fortran array, consider declaring the Fortran array with a zero origin:

integer a(0:99)

like, just do it. save yourself the pain πŸ₯²


πŸ’€ 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. 😳

the error handler can be changed with:

  • MPI_Comm_set_errhandler (for communicators)
  • MPI_File_set_errhandler (for files)
  • MPI_Win_set_errhandler (for RMA windows)

the MPI-1 routine MPI_Errhandler_set may still be used, but its use is deprecated. 🚩

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.

  • MPI_SUCCESS β€” no error; the MPI routine completed successfully. we love a successful routine πŸŽ‰
  • 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. (zero is valid, bestie, don't come for her πŸ’…)
  • 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.
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code.

and that's the whole page, no notes πŸŽ€

this was page MPI_Type_indexed(3) from the MPI manual, dated 4/10/2026 β€” go forth and index your datatypes, bestie, you got this πŸ¦‹πŸ’œβœ¨

πŸ“¦ where this page comes from