【问题标题】:how to use MPI_Scatterv() properly如何正确使用 MPI_Scatterv()
【发布时间】:2015-03-29 12:57:29
【问题描述】:

我在并行程序中使用 MPI_Scatterv 时遇到问题。这是它的定义方式:

int MPI_Scatterv(const void *sendbuf, const int *sendcounts,
    const int *displs, MPI_Datatype sendtype, void *recvbuf,
    int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)

按照我的理解,MPI_ScattervMPI_Scatter 之间的区别在于,MPI_Scatterv 中的段不必具有相同的长度,也不必是连续的(内存中的间隙被允许)。我不明白的部分是如果recvbuf 可以是每个进程的不同大小的数组,那么recvcount 应该使用什么。假设我想将 sendbuf 的 5 个元素发送到进程 0 和 15 到进程 1。recvcount 的值应该是什么?

【问题讨论】:

    标签: c++ c parallel-processing mpi


    【解决方案1】:

    每个进程都必须调用MPI_Scatterv,并使用正确的recvcount。您可以传递一个变量,其值取决于每个进程的排名。

    例如:

    int recvcount = (rank == 0) ? 5 : 15;
    
    MPI_Scatterv( sendbuf, sendcounts, displs, sendtype,
                  recvbuf, recvcount, recvtype, 0, MPI_COMM_WORLD );
    

    等级为0 的进程以recvcount5 调用MPI_Scatterv,而进程1 通过15 的计数。

    【讨论】:

      猜你喜欢
      • 2019-08-24
      • 2016-02-10
      • 1970-01-01
      • 2014-10-25
      • 2020-12-04
      • 2012-07-12
      • 2013-01-21
      • 2021-10-24
      • 2011-12-22
      相关资源
      最近更新 更多