Is ```MPI_REAL, MPI_INTEGER, MPI_COMPLEX, etc``` portable?

Just curious, does the MPI constants, those MPI_REAL, MPI_INTEGER, MPI_COMPLEX, etc the same type for all the machine (therefore portable)?
https://www.mpich.org/static/docs/v3.3/www3/Constants.html
Like, I take from the above webpage , the MPI constants and their correspondence to Fortran intrinsic type,

Fortran datatypes
MPI_REAL - REAL
MPI_INTEGER
INTEGER
MPI_LOGICAL
LOGICAL
MPI_DOUBLE_PRECISION
DOUBLE PRECISION
MPI_COMPLEX
COMPLEX
MPI_DOUBLE_COMPLEX
complex*16 (or complex*32) where supported.
The following datatypes are optional MPI_INTEGER1 - integer*1 if supported

MPI_INTEGER2
integer*2 if supported
MPI_INTEGER4
integer*4 if supported
MPI_INTEGER8
integer*8 if supported
MPI_INTEGER16
integer*16 if supported
MPI_REAL4
real*4 if supported
MPI_REAL8
real*8 if supported
MPI_REAL16
real*16 if supported
MPI_COMPLEX8
complex*8 if supported
MPI_COMPLEX16
complex*16 if supported
MPI_COMPLEX32
complex*32 if supported

If those MPI_XXX constants the portable, then perhaps I do not need to use mpi_sizeof() to define mine portable types anymore, like here,

1 Like

First, the MPI Forum deprecated MPI_SIZEOF because one should use C_SIZEOF or STORAGE_SIZE instead.

Second, these types are portable as long as the Fortran compiler flags used to build the MPI library and the application are the same. If the user decides to use -r8, -i8, -fdefault-integer-8 or some other flag that modifies the sizeof these types, then they will not work correctly. In that case, the user should employ either the fixed-size types (e.g. MPI_INTEGER8) or the output of MPI_TYPE_MATCH_SIZE.

Finally, users must understand that the MPI functions that take INTEGER arguments (not buffers) absolutely must be passed the correct size type for how the library was built. With rare exception, MPI libraries are built such that INTEGER is a 32-bit type. That means that if the user changes the default integer size in their application to another size (presumably, 64-bit), then they must use INTEGER*4 or equivalent for those arguments.

It is possible that users can get away with passing 64-bit integers for counts etc. when using the mpi_f08 module due to how large-count support is implemented (with polymorphism, such that INTEGER(KIND=MPI_COUNT_KIND) may match INTEGER*8) but this is not recommended, nor is it portable today, because Open-MPI does not support MPI 4.0 yet.

2 Likes