如果MPI_FLOAT_INT是什么c ++等效类型 [英] what is the c++ equivalent type if MPI_FLOAT_INT

查看:164
本文介绍了如果MPI_FLOAT_INT是什么c ++等效类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为mpi写一个type_traits库,但是当我将float int定义为MPI_FLOAT_INT的类型时,在声明错误中得到了两个或多个变量类型,那么c ++中MPI_FLOAT_INT的等效类型是什么?

I am writing a type_traits library for mpi, but when I define float int as a type for MPI_FLOAT_INT, I get two or more variable type in declaration error, what is the equivalent type of MPI_FLOAT_INT in c++?

推荐答案

唯一权威来源, MPI标准,将MPI_FLOAT_INT定义为(第5.9.4节 MINLOCMAXLOC ):

The only authoritative source, the MPI standard, defines MPI_FLOAT_INT as (Section 5.9.4 MINLOC and MAXLOC):

数据类型MPI_FLOAT_INT,就像由以下指令序列定义的.

type[0] = MPI_FLOAT
type[1] = MPI_INT
disp[0] = 0
disp[1] = sizeof(float)
block[0] = 1
block[1] = 1
MPI_TYPE_CREATE_STRUCT(2, block, disp, type, MPI_FLOAT_INT)

类似的语句适用于MPI_LONG_INTMPI_DOUBLE_INT.

这意味着该类型对应于struct { float a; int b; },但前提是必须保证在ab之间没有插入填充空间.在int是64位并且必须对齐8个字节的系统上可能不是这种情况.可能需要指示编译器生成打包结构,例如使用GCC:

It means that the type corresponds to struct { float a; int b; }, but only if there is guarantee that no padding space is inserted between a and b. This might not be the case on systems where int is 64-bit and has to be aligned on 8 bytes. One might need to instruct the compiler to generate packed structures, e.g. with GCC:

#pragma pack(push, 1)
struct float_int
{
   float a;
   int b;
}
#pragma pack(pop)

请注意,MPI_FLOAT_INT旨在用于MINLOCMAXLOC归约,以便找出最小/最大float值和保持该值的最低编号级别.

Note that MPI_FLOAT_INT is intended to be used in MINLOC and MAXLOC reductions in order to find out both the min/max float value and the lowest numbered rank that is holding it.

这篇关于如果MPI_FLOAT_INT是什么c ++等效类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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