MPI_Type_create_subarray(3)
π 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 typeoldtypelive in each dimension of the full array. positive integer energy only. πarray_of_subsizesβ how many elements of typeoldtypeare 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 uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call. commit your types first, bestie, please. πMPI_ERR_OTHERβ other error; useMPI_Error_stringto 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
- 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