MPI Gather different Size
c++, mpi
Solution
If the size of each piece differs you would use `MPI_Gatherv()` instead of `MPI_Gather()`. The same is also true for `MPI_Scatter()` vs `MPI_Scatterv()`.
Problem
I have a cluster of 10 computers and 2 variables in c++ - result : size int 100; - result_final : (only on host) size int 1000; how can I gather the pieces of 'result' and create 'result_final' as their size differs. Thank you! ``` int *rcounts = (int *) malloc(commSize * sizeof(int)); int *displs = (int *) malloc(commSize * sizeof(int)); for (i = 0; i < commSize; ++i) { displs[i] = commRank * result_size * size; rcounts[i] = result_size * size; } MPI_Gatherv(h_result, result_size * size, MPI_INT, h_result_final, rcounts, displs, MPI_INT, 0, MPI_COMM_WORLD); ```