7.5.1. Examples using MPI_GATHER, MPI_GATHERV

PreviousUpNext
Up: Gather Next: Scatter Previous: Gather

The examples in this section use intra-communicators.


Example Gather 100 ints from every MPI process in group to the root. See Figure 7.

Image file


Example Previous example modified---only the root allocates memory for the receive buffer.

Image file

Image file


Figure 7: The root gathers 100 ints from each MPI process in the group.


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.

Image file


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.

Image file

Note that the program is erroneous if stride < 100.

Image file


Figure 8: The root gathers 100 ints from each MPI process in the group, each set is placed stride ints apart.


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.

Image file

Image file


Figure 9: The root gathers column 0 of a 100$ x $150 C array, and each set is placed stride ints apart.


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.

Image file

Note that a different amount of data is received from each MPI process.

Image file


Figure 10: The root gathers 100-i ints from column i of a 100$ x $150 C array, and each set is placed stride ints apart.


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.

Image file


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.

Image file

Image file


Figure 11: The root gathers 100-i ints from column i of a 100$ x $150 C array, and each set is placed stride[i] ints apart (a varying stride).


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.

Image file


PreviousUpNext
Up: Gather Next: Scatter Previous: Gather


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023