MPI_Type_create_subarray(3)

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

πŸ’– MPI_Type_create_subarray β€” bestie edition πŸ’–

okay so this is from the MPI manual, and it's the one that makes you a datatype for a slice of a big regular multidimensional array. like, you have a giant N-dimensional grid and you're only allowed to touch a little rectangular chunk of it? this is the glow-up that makes that possible. ✨


✨ NAME ✨

MPI_Type_create_subarray β€” bestie, it creates a datatype for a subarray of a regular, multidimensional array. that's it, that's the whole vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

int MPI_Type_create_subarray(int ndims, const int array_of_sizes[],
const int array_of_subsizes[],
const int array_of_starts[], int order,
MPI_Datatype oldtype, MPI_Datatype *newtype)

int MPI_Type_create_subarray_c(int ndims, const MPI_Count array_of_sizes[],
const MPI_Count array_of_subsizes[],
const MPI_Count array_of_starts[], int order,
MPI_Datatype oldtype, MPI_Datatype *newtype)

yes there's a _c version with MPI_Count instead of int β€” she ate and left no crumbs. πŸ‘‘


πŸŽ€ INPUT PARAMETERS πŸŽ€

  • ndims β€” the number of array dimensions. must be a positive integer, no zero, no negatives, we don't do that here. πŸ’…
  • array_of_sizes β€” how many elements of type oldtype live in each dimension of the full array. positive integer energy only. 🌈
  • array_of_subsizes β€” how many elements of type oldtype are in each dimension of the subarray (aka the cute little chunk you actually want). also a positive integer. πŸ“
  • array_of_starts β€” the starting coordinates of the subarray in each dimension. non-negative integer, bestie, don't start at -1. πŸ™ˆ
  • order β€” the array storage order flag. it's a state. iykyk. 🌸
  • oldtype β€” the old datatype. a handle. the before picture. πŸ’œ

πŸ‘‘ OUTPUT PARAMETERS πŸ‘‘

  • newtype β€” the new datatype. a handle. the after picture. main character energy fr fr. ✨

πŸ’… THREAD AND INTERRUPT SAFETY πŸ’…

this routine is thread-safe. translation? multiple threads can use it at the same time and you do NOT need to bring your own user-provided thread locks. no cap. 🫢

BUT. and this is a big but β€” the routine is not interrupt safe. why? typically because it calls memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so, iconic, but don't interrupt her mid-glow-up. πŸ’€


🧚 NOTES FOR FORTRAN 🧚

every MPI routine in Fortran (except for MPI_WTIME and MPI_WTICK) gets an extra argument at the end of the argument list called ierr. 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. periodt. 🌟

and also: all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. that's just the rule, bestie. πŸ’–


😭 ERRORS 😭

every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β€” C routines as the value of the function, Fortran routines in the last argument. before that value comes back to you, the current MPI error handler gets called. and by default? that handler aborts the MPI job. like, whole thing, gone, goodbye. πŸ’€

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 β€” we don't stan deprecated behavior, bestie, lowkey let it go. πŸ™ˆ

the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned instead. and note: MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. so like, they'll try, but no promises. 😭

  • MPI_SUCCESS β€” no error; the MPI routine completed successfully. the slay outcome. ✨
  • 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. ok so zero can be fine, but negative is a no. πŸ’…
  • 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 your types first, bestie, please. πŸŽ€
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more information about this error code. the mystery box error, go look it up. πŸ”₯

ngl the whole "default handler aborts your job" thing is giving horror movie, so set MPI_ERRORS_RETURN if you wanna live dangerously (responsibly). 🌈

okay that's the whole page, bestie!! you understood it, you're literally so good at this, go build that subarray datatype and eat. πŸ’–βœ¨πŸŽ€

this lil lesson came from the MPI manual, MPI_Type_create_subarray(3), dated 4/10/2026. mwah, take care of her πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from