The displs
argument from MPI_Scatterv()
function is said to be an "integer array (of length group size). Entry i specifies the displacement (relative to sendbuf from which to take the outgoing data to process i".
Let's say then that I have sendcounts
argument
int sendcounts[7] = {3, 3, 3, 3, 4, 4, 4};
The way I'm reasoning this out is that the displs
array should always start with value of 0 since the first entry's displacement is 0 relative to sendbuf
, so in my example above, displs
should look like:
int displs[7] = {0, 3, 6, 9, 13, 17, 21};
Is that correct? I know this is a trivial question, but for some reason the web does not help at all. There are no good examples out there, hence my question.
Yes, displacements gives the root information the information as to which items to send to a particular task - the offset of the starting item. So in most simple cases (e.g., you'd use
MPI_Scatter
but the counts don't evenly divide) this can be immediately calculated from counts information:But it doesn't need to be that way; the only restriction is that the data you're sending can't overlap. You could count from the back just as well:
or any arbitrary order would work as well.
And in general the calculations can be more complicated because the types of the send buffer and receive buffers have to be consistent but not necessarily the same - you often get this if you're sending multidimensional array slices, for instance.
As an example of the simple cases, the below does the forward and backward cases:
Running gives: