MPI_Type_create_indexed_block(3)

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

πŸ’– 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 uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call. commit her first bestie, she's not ready 😀
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to 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