如果MPI_FLOAT_INT是什么c ++等效类型 [英] what is the c++ equivalent type if MPI_FLOAT_INT
问题描述
我正在为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节 MINLOC
和MAXLOC
):
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_INT
和MPI_DOUBLE_INT
.
这意味着该类型对应于struct { float a; int b; }
,但前提是必须保证在a
和b
之间没有插入填充空间.在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
旨在用于MINLOC
和MAXLOC
归约,以便找出最小/最大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屋!