The indexed constructor is a new one. But it works similarly
to those collective communication operations that allow for
contributions of various sizes from participating processes, e.g.,
MPI_Gatherv or MPI_Allgatherv. The MPI_Type_indexed
synopsis in C is:
MPI_Type_indexed(int count, int *array_of_blocklengths,
int *array_of_displacements, MPI_Datatype oldtype,
MPI_Datatype *newtype)
and its Fortran synopsis is:
mpi_type_indexed(count, array_of_blocklengths, arrray_of_displacements,
oldtype, newtype, ierror)
integer count, array_of_blocklengths(*), array_of_displacements(*),
oldtype, newtype, ierror
This function works as follows. We are going to put together
count blocks of data of type oldtype. The blocks may
be of different length now, and because they may be of different lengths
their corresponding displacements may be different for every block
too, so we can no longer just give a single stride value
for the blocks. For every block we have to define separately its
length and its offset from the beginning of the array, i.e.,
its displacement. If we are going to have count blocks,
their lengths and displacements are specified on two arrays
of integers, each count elements long. The arrays are
array_of_blocklengths and array_of_displacements.
But other than that these functions still work much like
MPI_Type_vector. In fact MPI_Type_vector can be
viewed as a specific case of MPI_Type_indexed and
it can be implemented as such. In particular all blocks comprise
items of the same data type.
Here is an example that illustrates how this function works.
Consider the same oldtype as above, i.e.,
the named_double. Its map is:
named_double = {(double,0), (char, 8)}
We are now going to call:
What is going to be theMPI_Type_indexed(2, (3,1), (4,0), named_double, &newtype)
newtype map? We are going to put together
2 blocks of data items of type named_double. The first block
has length 3 and offset 4. The second block has length 1 and offset
0. Observe that we are changing here the order of data, sic!
Here is the map of this new MPI data type:
newtype =
{(double, 64), (char, 72), (double, 80), (char, 88), (double, 96), (char, 104),
(double, 0), (char, 8)}
There is also a variant of this function that lets MPI programmers specify displacements in bytes rather than in extents of the basic data type used in the operation. The synopsis of this function in C is:
MPI_Type_hindexed(int count, int *array_of_blocklengths,
MPI_Aint *array_of_displacements, MPI_Datatype oldtype,
MPI_Datatype *newtype)
where array_of_displacements contains displacements in
bytes. The Fortran interface is:
mpi_type_hindexed(count, array_of_blocklengths, array_of_displacements,
oldtype, newtype, ierror)
integer count, array_of_blocklengths(*), array_of_displacements(*)
oldtype, newtype, ierror