【问题标题】:MPI Gather different SizeMPI 收集不同的大小
【发布时间】:2012-05-08 17:19:45
【问题描述】:

我有一个由 10 台计算机和 2 个 C++ 变量组成的集群 - 结果:大小 int 100; - result_final : (仅在主机上) size 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);

【问题讨论】:

  • 如果您向我们展示您编写的代码,这里的人会有所帮助。如果你不在这里的人会添加无用的 cmets(比如这个)。

标签: c++ mpi


【解决方案1】:

如果每件的尺寸不同,您可以使用MPI_Gatherv() 而不是MPI_Gather()MPI_Scatter()MPI_Scatterv() 也是如此。

【讨论】:

  • 所以我可以这样做吗? MPI_Gatherv(h_result, result_size * size, MPI_INT, h_result_final, displs, rcounts, MPI_INT, 0, MPI_COMM_WORLD); ?
  • 你看MPI_Gatherv的描述了吗?如果您要收集相同大小的碎片,请使用MPI_Gather。请看一下文档 - 它非常有用!
  • 为什么?这就是我的代码... int *rcounts = (int *) malloc(commSize * sizeof(int)); int *displs = (int *) malloc(commSize * sizeof(int)); for (i = 0; i
  • 由于你的计数都是一样的,你最好使用MPI_Gather。这在您最初的问题中并不明显。
  • 应该是:MPI_Gatherv(h_result, result_size * size, MPI_INT, h_result_final, result_size * size, MPI_INT, 0, MPI_COMM_WORLD);。您从问题中删除了之前的代码示例,所以我不确定您是否应该将两个大小参数都乘以 size。请注意,MPI_GatherMPI_Gatherv 中的大小都是在元素中指定的,而不是在字节中。
猜你喜欢
  • 2013-11-13
  • 2018-11-04
  • 2011-12-13
  • 2015-06-02
  • 2016-09-28
  • 1970-01-01
  • 2011-06-15
  • 2016-10-23
相关资源
最近更新 更多