Why using `MPI_Type_vector` for specifying a stride gap?

873 views Asked by At

In the MPI documentation I read that the difference between MPI_Type_vector and MPI_Type_contiguos is that the first allows to specify a stride gap between the elements of the array.

Why one should be interested in doing that instead of using simply a MPI_Type_contiguous?

1

There are 1 answers

0
Gilles Gouaillardet On BEST ANSWER

You can see MPI_Type_contiguous() as a special case of MPI_Type_vector() with no stride.

For example, in Fortran, arrays are column major. so if you consider the following array

integer :: A(n,m)

The derived datatype for a column can be obtained with

CALL MPI_Type_contiguous(n, MPI_INTEGER, newtype, ierr)

or

CALL MPI_Type_vector(n, 1, 1, MPI_INTEGER, newtype, ierr)

or

CALL MPI_Type_vector(1, n, n, MPI_INTEGER, newtype, ierr)

But the only way to describe a row is via MPI_Type_vector()

CALL MPI_Type_vector(m, 1, n, MPI_INTEGER, newtype, ierr)

Note that if you want to send/receive several rows at once, you will need to resize the datatype, so the full sequence would be

CALL MPI_Type_vector(m, 1, n, MPI_INTEGER, tmptype, ierr)
CALL MPI_Type_size(MPI_INTEGER, integer_size, ierr)
CALL MPI_Type_create_resized(tmptype, 0, integer_size, newtype, ierr)
CALL MPI_Type_free(tmptype, ierr)