MPI_Get_count中的未知MPI_Datatype

时间:2016-10-20 08:54:22

标签: c++ mpi c++14 openmpi

我想将struct S的几个实例发送到某些进程。每个struct的布局可能不同,也就是说,s.v可能有不同的大小。在接收数据时,我不知道MPI_Datatype中的确切MPI_Get_count,因为该信息仅在发件人流程中可用。还要考虑struct S有很多非原始成员,因此在接收时我不能将MPI_Datatype假设为MPI_INT。如何获取用于MPI_Datatype的{​​{1}}?

MPI_Get_count

1 个答案:

答案 0 :(得分:0)

MPI messages are generally typeless, that is, they do not carry the datatypes in them. There is no way on the receiver side to obtain detailed information about the message structure. A viable option is to send the structure as two messages. The first one will contain some kind of description, e.g., the length of each vector. Once received, that information is used by the receiver to prepare the data object and to construct the appropriate datatype. Then, the second message will transmit the actual data. Boost.MPI completely automates this process - check its source code to learn how.

Another option is to pack the description with the data in a single message using MPI_Pack. On the receiver side, the message size could be probed with type MPI_PACKED and the data should be unpacked using MPI_Unpack. I don't think the added complexity of this case will offset the small performance loss due to sending two messages instead of one.

In your case that is not necessary as your structure has a single member, which is a vector of integers. Therefore, the correct type to give to MPI_Get_count is MPI_INT.