MPI_Type_indexed(3)
π 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 inarray_of_displacementsandarray_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 ofoldtype. 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 uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call.MPI_ERR_OTHERβ other error; useMPI_Error_stringto 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
- 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