I\'m having trouble getting MPI_Gatherv
to work with a std::vector. I have written a small program that should fill a vector with integers of rank+1 (to avoid 0 as
The issue isn't with std::vector; there's just a typo in your code calculating the displacements. This:
for(int i=0; i<p; ++i) {
rcounts[i] = X/p;
rdisp[i] = my_rank*(X/p);
}
Should be this:
for(int i=0; i<p; ++i) {
rcounts[i] = X/p;
rdisp[i] = i*(X/p);
}
As it was, for rank zero (which in this case is the only place where the displacement array matters), all the displacements were zero, so everything was getting written to the start of the array, and the second half of the array was untouched.