如何正确使用MPI_Scatterv() [英] how to use MPI_Scatterv() properly

查看:1999
本文介绍了如何正确使用MPI_Scatterv()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在并行程序中使用 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_Scatterv MPI_Scatter 之间的区别是在 MPI_Scatterv 段不必具有相同的长度,并且它们不必是连续的(允许在存储器中存在间隙)。我不明白的部分是如果 recvbuf 可以是每个进程不同大小的数组,那么应该使用 recvcount 。假设我想发送sendbuf的5个元素来处理0和15来处理1. recvcount 的值应该是什么?

解决方案

每个进程都必须调用 MPI_Scatterv ,右边 recvcount 。您可以传递值取决于每个进程排名的变量。



例如:

  int recvcount =(rank == 0)? 5:15; 

MPI_Scatterv(sendbuf,sendcounts,displs,sendtype,
recvbuf,recvcount,recvtype,0,MPI_COMM_WORLD);

处理等级 0 $ c> MPI_Scatterv 与 recvcount 5 1 传递 15 的计数。


I am having a problem using MPI_Scatterv in a parallel program. Here is how it is defined :

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)

The way I understood it , the difference between MPI_Scatterv and MPI_Scatter is the fact that in MPI_Scatterv segments do not have to be of the same length and they don't have to be continuous (gaps in memory are allowed). The part I do not understand is if the recvbuf can be an array of different size for each process then what should be used for recvcount. Let's say I want to send 5 elements of sendbuf to process 0 and 15 to process 1. What should the value of recvcount be?

解决方案

Each process has to call MPI_Scatterv with the right recvcount. You can pass a variable whose value depends on the rank of each process.

For example:

int recvcount = (rank == 0) ? 5 : 15;

MPI_Scatterv( sendbuf, sendcounts, displs, sendtype,
              recvbuf, recvcount, recvtype, 0, MPI_COMM_WORLD );

Process with rank 0 calls MPI_Scatterv with a recvcount of 5 whereas process 1 passes a count of 15.

这篇关于如何正确使用MPI_Scatterv()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆