MPI中的相同发送和接收缓冲区 [英] Same send and receive buffers in MPI

查看:85
本文介绍了MPI中的相同发送和接收缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,每个进程都在数组的某些部分上工作.我希望每个进程将其处理的部分发送给其他进程,并从其他进程接收其他部分.为此,我使用了MPI_Allgatherv,但是我将发送和接收缓冲区保持不变:

In my code, each process works on certain portion of an array. I want each process to send the portion it worked on to other processes and receive other portions from other processes. For this I used MPI_Allgatherv but I kept send and receive buffers the same:

MPI_Allgatherv (&vel[0],  localSizesFaceV[rank], MPI_DOUBLE, &vel[0],  localSizesFaceV, displsFaceV, MPI_DOUBLE, MPI_COMM_WORLD);

我以前将此功能用于其他目的,并使用了不同的发送和接收缓冲区,并且它可以正常工作.这就是为什么我确定其他参数没有问题的原因.

I used this function before for other purposes with different send and receive buffers and it worked. That is why I am sure there is no problem with other parameters.

在2个进程的情况下,其中一个进程不返回.当我将发送缓冲区复制到另一个std::vector

In the case of 2 processes, one of the processes does not return. When I copied send buffer to another std::vector

vector <double> vel2;
vel2 = vel;

并使用vel2作为发送缓冲区,然后返回所有进程.为什么?

and used vel2 as send buffer then all processes returned. Why?

推荐答案

通常,MPI要求该参数不具有别名.在当前标准的第2.3章中明确提及.

Generally speaking, MPI requires that the argument is not aliased. This is explicitly mentioned chapter 2.3 of the current standard.

除非另外指定,否则为OUT类型或INOUT类型的参数 不能使用传递给MPI过程的任何其他参数作为别名.

Unless specified otherwise, an argument of type OUT or type INOUT cannot be aliased with any other argument passed to an MPI procedure.

这说明了您的代码有问题的原因.但是,可以很容易地解决您的问题,而不必显式复制缓冲区:MPI_IN_PLACE关键字.它指定在相关时也将使用输出缓冲区作为输入缓冲区就地"进行通信.

This explains why your code has problems. However, there is the possibility to solve your issue very easily, without having to explicitly copy your buffer: the MPI_IN_PLACE keyword. It specifies that the communication will be done "in-place" using the output buffer as an input buffer too wherever relevant.

您的代码将变为:

MPI_Allgatherv( MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, &vel[0],  localSizesFaceV, displsFaceV, MPI_DOUBLE, MPI_COMM_WORLD);

NB:用于发送缓冲区的实际类型无关紧要.您可以根据需要保留MPI_DOUBLE,但我倾向于使用MPI_DATATYPE_NULL来表明该参数将被忽略.

NB: the actual type to use for the send buffer is irrelevant. You can keep MPI_DOUBLE if you want to, but I tend to prefer using MPI_DATATYPE_NULL to make clear that the parameter is ignored.

这篇关于MPI中的相同发送和接收缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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