Problem with MPI_Gatherv for std::vector

后端 未结 1 1755
感情败类
感情败类 2021-01-26 23:52

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

相关标签:
1条回答
  • 2021-01-27 00:19

    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.

    0 讨论(0)
提交回复
热议问题