如何正确使用MPI_Scatterv() [英] how to use MPI_Scatterv() properly
问题描述
我在并行程序中使用 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
andMPI_Scatter
is the fact that inMPI_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 therecvbuf
can be an array of different size for each process then what should be used forrecvcount
. Let's say I want to send 5 elements of sendbuf to process 0 and 15 to process 1. What should the value ofrecvcount
be?解决方案Each process has to call
MPI_Scatterv
with the rightrecvcount
. 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
callsMPI_Scatterv
with arecvcount
of5
whereas process1
passes a count of15
.这篇关于如何正确使用MPI_Scatterv()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!