我有一个由 10 台计算机和 2 个 C++ 变量组成的集群 - 结果:大小 int 100; - result_final:(仅在主机上)大小 int 1000; 我怎样才能收集“结果”的片段并创建“result_final”,因为它们的大小不同。 谢谢!
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);
最佳答案
如果每 block 的大小不同,您将使用 MPI_Gatherv()
而不是 MPI_Gather()
。 MPI_Scatter()
与 MPI_Scatterv()
也是如此。
关于c++ - MPI 收集不同尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10495139/