The examples in this section use intra-communicators.
Example
Gather 100 ints from every MPI process in group to the root. See
Figure 7.
Example
Previous example modified---only the root allocates memory for the
receive buffer.
Example
Do the same as the previous example, but use a derived datatype. Note that
the type cannot be the entire set of gsize*100 ints since type matching
is defined pairwise between the root and each MPI process in the gather.
Example
Now have each MPI process send 100 ints to the root, but place each set (of 100)
stride ints apart at the receiving end. Use MPI_GATHERV
and the displs
argument to achieve this effect. Assume stride ≤ 100.
See Figure 8.
Note that the program is erroneous if stride < 100.
Example
Same as Example Examples using MPI_GATHER, MPI_GATHERV on the receiving side, but send the
100 ints from the 0th column of a
100×150 int array, in C. See Figure 9.
Example
MPI process i sends (100-i) ints from the i-th column of a
100 × 150 int array, in C. It is received into a buffer with stride,
as in the previous two examples. See Figure 10.
Note that a different amount of data is received from each MPI process.
Example
Same as Example Examples using MPI_GATHER, MPI_GATHERV, but done in a different way at the sending end.
We create a datatype that causes the correct striding at the
sending end so
that
we read a column of a C array.
A similar thing was done in Example Examples,
Section Examples.
Example
Same as Example Examples using MPI_GATHER, MPI_GATHERV at sending side, but
at receiving side we make the
stride between received blocks vary from block to block.
See Figure 11.
Example
MPI process i sends num ints from the i-th column of a
100 × 150 int array, in C. The complicating factor is that
the various values of num are not known to root, so a
separate gather must first be run to find these out. The data is
placed contiguously at the receiving end.