做派的MPI数据类型/接收必须匹配? [英] Do MPI Datatypes of Send/Receive Have to Match?

查看:100
本文介绍了做派的MPI数据类型/接收必须匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来确定发送操作的是什么参数和传递信息接收操作必须匹配。

I'm trying to determine what parameters of a sending operation and receiving operation must match for a message to be passed.

据我了解,接收操作必须在信息,标签和通信器的源相匹配,(或包含)。然而,就是要匹配其所需的数据类型?

I understand that a receiving operation must match (or encompass) the source of the message, the tag and the communicator. However, is it required for the datatype to be matching?

例如。我可以发送一个从0级匹配:

E.g. could I match a send from rank 0:

MPI_Send (send_buffer, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);

与等​​级1的接收操作:

with the receiving operation on rank 1:

MPI_Recv (recv_buffer, 4, MPI_BYTE, 0, 0, MPI_COMM_WORLD, status);

特别地作为发送'计数'小于接收计数,其我知道是有效的MPI

Particularly as the sending 'count' is less than the receiving count, which I am aware is valid for MPI.

感谢。

推荐答案

简短的回答是肯定的,数据类型必须匹配,但也有一些注意事项。

The short answer is yes, datatypes must match, but there are some caveats.

在使用基本的MPI数据类型,如 MPI_INT MPI_FLOAT 的类型必须相同。唯一的例外是 MPI_PACKED ,它可以匹配任何其他类型的。

When using primitive MPI datatypes such as MPI_INT and MPI_FLOAT, the types must be identical. The only exception is MPI_PACKED, which can match any other type.

在使用派生数据类型(也称为用户定义的数据类型),事情变得稍微复杂一些。一般MPI数据类型包括两个方面:一个类型签名,它定义了基本的语言数据类型构成派生数据类型,以及一系列字节的位移,它定义在哪里这些基本元素驻留在内存中。两个序列的组合称为数据类型的类型映射。原始MPI数据类型是具有在式签名的单个基本数据类型为0的位移,例如一般的数据类型的特定情况下,例如 MPI_INT 有以下类型映射: {(INT,0)} 。对于发送和接收操作匹配,的类型签名的必须是双方的相同,但位移的可能会有所不同。例如。发送者可以发送包括3 MPI_FLOAT 让一个 MPI_Type_contiguous 对象,但是接收器可以接收这是一个 MPI_Type_indexed 类型3 MPI_FLOAT s的任意位移。发件人可能还提供3 MPI_FLOAT 元素,例如数组 MPI_SEND(BUF,3,MPI_FLOAT,...),这仍然会导致同一类型的签名。

When using derived datatypes (a.k.a. user-defined datatypes), things get slightly more complicated. A general MPI datatype consists of two things: a type signature, which defines the basic language datatypes that make up the derived datatype, and a series of byte displacements, which define where those basic elements reside in memory. The combination of both sequences is called the type map of the datatype. The primitive MPI datatypes are particular cases of such general datatypes having a single basic datatype in the type signature with a displacement of 0, e.g. MPI_INT has the following type map: { (int, 0) }. For a Send and Receive operation to match, the type signature must be the same on both sides, but the displacements can vary. E.g. the sender might send a single MPI_Type_contiguous object consisting of 3 MPI_FLOATs, but the receiver can receive this as an MPI_Type_indexed type of 3 MPI_FLOATs with arbitrary displacements. The sender might also supply an array of 3 MPI_FLOAT elements, e.g. MPI_Send(buf, 3, MPI_FLOAT, ...) and this would still result in the same type signature.

我要强调的是类型签名只包含基本的数据类型。是否用户定义的数据类型是从原始的MPI类型或其他用户定义的数据类型直接创建(或者它们的混合物)是不相关的。

I should emphasize that the type signature consists of basic datatypes only. Whether the user-defined datatype was created directly from primitive MPI types or other user-defined datatypes (or a mixture of thereof) is irrelevant.

例如:发送者定义了一个 MPI_Type_struct 包括3 MPI_INT 和2 MPI_FLOAT 秒。接收器定义了一个 MPI_Type_contiguous 包括3 MPI_INT S(我们称之为键入 A ),另一个 MPI_Type_contiguous MPI_FLOAT S(键入 B <中> / code>),然后一个 MPI_Type_struct 由1 A 1 B的。这两个数据类型将匹配,因为最终他们都3 INT 紧随其后是2 浮动秒。

Example: the sender defines an MPI_Type_struct consisting of 3 MPI_INTs and 2 MPI_FLOATs. The receiver defines an MPI_Type_contiguous consisting of 3 MPI_INTs (let's call this type A), another MPI_Type_contiguous of 2 MPI_FLOATs (type B), and then an MPI_Type_struct consisting of 1 A and 1 B. These two datatypes will match, since ultimately they're both 3 ints followed by 2 floats.

这篇关于做派的MPI数据类型/接收必须匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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