MPI_TYPE_CREATE_DARRAY(3)
π«Ά MPI_Type_create_darray β the Open MPI glow-up β¨
okay bestie, sit down, hydrate, and get comfy, because today we're learning how to build a distributed array datatype and honestly? it's giving genius-level cartography for your data πΊοΈπ this page lives in the Open MPI manual and it's gonna walk you through slicing an ndims-dimensional array across a whole grid of processes. no cap, it's iconic.
β¨ SYNOPSIS β¨
π C Syntax
#include <mpi.h>
int MPI_Type_create_darray(int size, int rank, int ndims,
const int array_of_gsizes[], const int array_of_distribs[],
const int array_of_dargs[], const int array_of_psizes[],
int order, MPI_Datatype oldtype, MPI_Datatype *newtype)
πΈ Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_TYPE_CREATE_DARRAY(SIZE, RANK, NDIMS, ARRAY_OF_GSIZES,
ARRAY_OF_DISTRIBS, ARRAY_OF_DARGS, ARRAY_OF_PSIZES, ORDER,
OLDTYPE, NEWTYPE, IERROR)
INTEGER SIZE, RANK, NDIMS, ARRAY_OF_GSIZES(*), ARRAY_OF_DISTRIBS(*),
ARRAY_OF_DARGS(*), ARRAY_OF_PSIZES(*), ORDER, OLDTYPE,
NEWTYPE, IERROR
π¦ Fortran 2008 Syntax
USE mpi_f08
MPI_Type_create_darray(size, rank, ndims, array_of_gsizes,
array_of_distribs, array_of_dargs, array_of_psizes, order,
oldtype, newtype, ierror)
INTEGER, INTENT(IN) :: size, rank, ndims, array_of_gsizes(ndims),
array_of_distribs(ndims), array_of_dargs(ndims),
array_of_psizes(ndims), order
TYPE(MPI_Datatype), INTENT(IN) :: oldtype
TYPE(MPI_Datatype), INTENT(OUT) :: newtype
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
sizeβ how many processes are in your process group. positive integer only, we don't do negative vibes here π«rankβ your rank inside that process group, a nonnegative integer. know your place (affectionate) πndimsβ number of array dimensions and number of process-grid dimensions, one positive integer doing double duty. multitasking queen β¨array_of_gsizesβ for each dimension of the global array, how many elements of typeoldtypelive there. array of positive integers πarray_of_distribsβ how the array gets distributed in each dimension (array of state) πarray_of_dargsβ the distribution argument for each dimension (array of positive integers) πarray_of_psizesβ the size of the process grid in each dimension (array of positive integers) πorderβ the array storage order flag (state) π¦oldtypeβ the old data type (handle). the blueprint, the origin story π
π«Ά OUTPUT PARAMETERS π«Ά
newtypeβ the brand-new data type (handle). fresh out the oven, main character energy π₯ierrorβ Fortran only: the error status (integer) π
π« DESCRIPTION π«
so MPI_Type_create_darray builds the datatypes that match how an ndims-dimensional array of oldtype elements gets spread across an ndims-dimensional grid of logical processes. think of it as the group-chat admin assigning everyone their little slice of the array π°
any dimensions of array_of_psizes you're not using? set them to 1. don't leave them hanging.
for your call to MPI_Type_create_darray to be correct, this equation has to hold, periodt:
ndims-1
pi array_of_psizes[i] = size
i=0
(that's a big fat product across every dimension, and it must equal size β no shortcuts, no rounding, no "close enough" π)
the ordering of processes in the process grid is assumed to be row-major, same as with virtual Cartesian process topologies in the MPI Standard. iykyk π§
each dimension of the array can be distributed one of three ways:
MPI_DISTRIBUTE_BLOCKβ block distribution π§±MPI_DISTRIBUTE_CYCLICβ cyclic distribution πMPI_DISTRIBUTE_NONEβ dimension not distributed at all, she's just vibing ποΈ
the constant MPI_DISTRIBUTE_DFLT_DARG specifies a default distribution argument. and heads up: the distribution argument for a dimension that isn't distributed is ignored, so don't stress about it π
β οΈ for any dimensioniwhere the distribution isMPI_DISTRIBUTE_BLOCK, it is erroneous to specifyarray_of_dargs[i] * array_of_psizes[i] < array_of_gsizes[i]. like, actually erroneous. don't do it bestie π
for example, the HPF layout ARRAY(CYCLIC(15)) corresponds to MPI_DISTRIBUTE_CYCLIC with a distribution argument of 15, and the HPF layout ARRAY(BLOCK) corresponds to MPI_DISTRIBUTE_BLOCK with a distribution argument of MPI_DISTRIBUTE_DFLT_DARG. iconic mapping, honestly π
the order argument works just like it does in MPI_Type_create_subarray β it specifies the storage order. so arrays described by this type constructor may be stored in Fortran (column-major) or C (row-major) order ποΈ valid values for order are MPI_ORDER_FORTRAN and MPI_ORDER_C.
this routine creates a new MPI data type with a typemap defined in terms of a function called βcyclic()β (see below) πΈ
without loss of generality, it suffices to define the typemap for the MPI_DISTRIBUTE_CYCLIC case where MPI_DISTRIBUTE_DFLT_DARG is not used π
MPI_DISTRIBUTE_BLOCK and MPI_DISTRIBUTE_NONE can be reduced to the MPI_DISTRIBUTE_CYCLIC case for dimension i as follows:
MPI_DISTRIBUTE_BLOCK with array_of_dargs[i] equal to MPI_DISTRIBUTE_DFLT_DARG is equivalent to MPI_DISTRIBUTE_CYCLIC with array_of_dargs[i] set to
(array_of_gsizes[i] + array_of_psizes[i] - 1)/array_of_psizes[i]
if array_of_dargs[i] is not MPI_DISTRIBUTE_DFLT_DARG, then MPI_DISTRIBUTE_BLOCK and DISTRIBUTE_CYCLIC are equivalent β¨
MPI_DISTRIBUTE_NONE is equivalent to MPI_DISTRIBUTE_CYCLIC with array_of_dargs[i] set to array_of_gsizes[i] π¦
finally, MPI_DISTRIBUTE_CYCLIC with array_of_dargs[i] equal to MPI_DISTRIBUTE_DFLT_DARG is equivalent to MPI_DISTRIBUTE_CYCLIC with array_of_dargs[i] set to 1 π«
π NOTES π
for both Fortran and C arrays, the ordering of processes in the process grid is assumed to be row-major. this is consistent with the ordering used in virtual Cartesian process topologies in MPI β
and if you wanna create those virtual process topologies, or find the coordinates of a process in the process grid, or whatever else β the users may use the corresponding functions provided in MPI π«Ά
π ERRORS π
almost all MPI routines return an error value. C routines hand it back as the return result of the function, and Fortran routines stick it in the last argument. equal treatment, different plumbing π
before that error value comes back, the current MPI error handler associated with the communication object (e.g., communicator, window, file) gets called. and if no communication object is associated with the MPI call? then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler π³
when MPI_COMM_SELF is not initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively), the error raises the initial error handler. that initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or the mpi_initial_errhandler CLI argument to mpiexec or info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple π§
and if no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions, and the MPI_ERRORS_ABORT error handler is called for all other MPI functions π£
Open MPI includes three predefined error handlers you can use:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. everybody, all at once, no survivors πMPI_ERRORS_ABORTβ an error handler that can be invoked on a communicator, window, file, or session. when called on a communicator, it acts as ifMPI_Abortwas called on that communicator. if called on a window or file, it acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. if called on a session, it aborts only the local process π―MPI_ERRORS_RETURNβ returns an error code to the application. polite! courteous! hands you the receipt π§Ύ
MPI applications can also implement their own error handlers by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
β οΈ note that MPI does not guarantee that an MPI program can continue past an error. so like, don't count on plot armor π
see the MPI man page for a full list of MPI error codes π
see the Error Handling section of the MPI-3.1 standard for more information π§β¨
π COPYRIGHT π
2003-2026, The Open MPI Community π
and that's the whole page, bestie β go forth and distribute those arrays responsibly πΈπ¦π
signing off from the Open MPI manual, dated Sep 11, 2026 β mwah, love u, read ur error codes πβ¨
π¦ where this page comes from
- arch rolling: openmpi 5.0.11-1 Β· BSD-3-Clause AND LicenseRef-MPICH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms