MPI_Type_create_indexed_block(3)
π MPI_Type_create_indexed_block(3) β the MPI manual, bestie edition π
okay so this one is from the MPI manual, and it's literally the glow-up that lets you build a datatype out of constant-sized blocks scattered wherever you want. main character energy fr fr.
β¨ NAME β¨
MPI_Type_create_indexed_block β create an indexed datatype with constant-sized blocks π¦
πΈ SYNOPSIS πΈ
int MPI_Type_create_indexed_block(int count, int blocklength,
const int array_of_displacements[],
MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_create_indexed_block_c(MPI_Count count, MPI_Count blocklength,
const MPI_Count array_of_displacements[],
MPI_Datatype oldtype,
MPI_Datatype *newtype)
π INPUT PARAMETERS π
countβ the length of the array of displacements, and it's a non-negative integer bestie, no negative vibes allowed πblocklengthβ how big each block is (non-negative integer, again with the non-negative, they're so serious about it)array_of_displacementsβ the array of displacements (integers)oldtypeβ the old datatype (a handle)
π OUTPUT PARAMETERS π
newtypeβ the brand new datatype (a handle). she's new here, be nice π«Ά
π₯ THREAD AND INTERRUPT SAFETY π₯
This routine is thread-safe. Which means you can throw it at multiple threads at once and it will not need you to bring your own thread locks β she handles herself, periodt. π
But β and this is the part where we all go π β the routine is not interrupt safe. Typically this is because it uses memory allocation routines like malloc, or other non-MPICH runtime routines, and those are themselves not interrupt-safe. so like, don't Ctrl+C her mid-glow-up, mmkay?
π NOTES FOR FORTRAN π
Every MPI routine in Fortran (except for MPI_WTIME and MPI_WTICK) gets an extra argument called ierr tacked onto the end of the argument list. ierr is an integer, and it means exactly the same thing as the return value of the routine does in C. Also, in Fortran, MPI routines are subroutines and you invoke them with the call statement.
And all MPI objects β like MPI_Datatype and MPI_Comm β are of type INTEGER in Fortran. no cap. β
π¦ NOTES π¦
The indices are displacements, and they're based on a zero origin. A common error β and this is the classic, the one everyone does, the it's-giving-2026-of-it-all β is doing something like this:
integer a(100)
integer blens(10), indices(10)
do i=1,10
10 indices(i) = 1 + (i-1)*10
call MPI_TYPE_CREATE_INDEXED_BLOCK(10,1,indices,MPI_INTEGER,newtype,ierr)
call MPI_TYPE_COMMIT(newtype,ierr)
call MPI_SEND(a,1,newtype,...)
Like, you expect this to send "a(1),a(11),..." because the indices have values "1,11,...". π But nope. Because these are displacements from the beginning of "a", it actually sends "a(1+1),a(1+11),...". bestie... the off-by-one jumped out. π
If you wish to consider the displacements as indices into a Fortran array, consider declaring the Fortran array with a zero origin:
integer a(0:99)
slay, problem solved. π β¨
π 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 that last argument. Before the value is returned, the current MPI error handler gets called. By default, this error handler aborts the MPI job. π
You can change the error handler 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 β like, it's giving old money but in a bad way. The predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned instead.
And note that MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. she tries her best okay π«Ά
MPI_SUCCESSβ no error; MPI routine completed successfully. ate that π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_COUNTβ invalid count argument. Count arguments must be non-negative; a count of zero is often valid. (zero is valid!! not always, but often, read the room)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 her first bestie, she's not ready π€MPI_ERR_OTHERβ other error; useMPI_Error_stringto get more information about this error code.
π that's the whole page, no skips, no skims. every flag, every error code, every warning β all present and accounted for, iykyk.
anyway that's the tea. this page came out of the MPI manual, dated 4/10/2026, and it's MPI_Type_create_indexed_block(3) β same title, same manual, same date, just with π
on top. go build something iconic with your constant-sized blocks bestie, ily, bye! ππ¦β¨
π¦ 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