In the following portion of the code the nodes quickly find their
own segments within particle array that is yet to be initialised.
Once they find their offsets the master process collects
them from every node and assembles them into array offsets.
This array, however, is known only to the master because
MPI_Gather
is used instead of MPI_Allgather
:
displacements[0] = 0; for (i = 1; i < pool_size; i++) displacements[i] = displacements[i-1] + counts[i-1]; total_particles = displacements[pool_size - 1] + counts[pool_size - 1]; my_offset = displacements[my_rank]; MPI_Gather ( &my_offset, 1, MPI_INT, offsets, 1, MPI_INT, host_rank, MPI_COMM_WORLD );
MPI_Gather
is discussed in section
4.5,
page 94, of
``MPI: A Message-Passing Interface Standard''. Numerous examples of
using MPI_Gather
are covered in section
4.5.1.