Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
924 views
in Technique[技术] by (71.8m points)

mpi - what is the c++ equivalent type if 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++?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

The datatype MPI_FLOAT_INT is as if defined by the following sequence of instructions.

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)

Similar statements apply for MPI_LONG_INT and MPI_DOUBLE_INT.

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)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...