[MPI3 Fortran] Serious problem with alignment of MPI_DOUBLE_PRECISION
N.M. Maclaren
nmm1 at cam.ac.uk
Wed Sep 28 05:17:00 CDT 2011
On Sep 28 2011, William Gropp wrote:
>
>This entire problem comes from the natural but mistaken idea that the
>MPI library should assign some default padding when creating a
>datatype. This is a bad idea because the alignment rules can depend
>on compiler switches or other compiler-specific choices; for example,
>some compilers allow the user to select between always 8 byte
>alignment, leading to structures that might have gaps but permit the
>uniform use of faster load operations or 4 byte alignment, but at a
>potential performance cost. In other words, even for a single
>compiler, there need not be a unique choice of extent, and hence this
>problem is insoluble.
Yes. In fact, for Fortran derived types other than SEQUENCE and BIND(C)
and for all C structs, there is no reason for the rules to be the same
for every type even in a single file and compilation. The only cases
where the rules must be the same for C are for compatible structs and
ones with a common initial sequence.
> Further, it is not necessary - the user can
>either create the datatype with the appropriate extent (by using
>MPI_UB) or resize it appropriately (with MPI_TYPE_CREATE_RESIZED since
>MPI 2.0). Rather than continue to get this wrong, I recommend simply
>telling the user not to assume that the MPI library can always divine
>how the compiler is going to chose to pad a derived type or struct.
>We can add an advice to users here that explains the problem and
>recommends using the existing MPI features to handle this problem.
>This is better coding and will affect few users.
It assuredly avoids MPI getting tangled up in a particularly foul area
of the languages more than is necessary, and would help to future-proof
the specification!
As far as users are concerned, my limited survey of open-source scientific
codes found no examples that would be affected, and I have never seen a
user code that would, either. However, that's merely my experience, and
I don't claim that it is representative of all MPI communities.
The issue of Fortran DOUBLE PRECISION versus C double in simple arrays
remains, but Fab Tillier has described what the Fortran standard itself
says about the matter.
Regards,
Nick Maclaren.
More information about the mpiwg-fortran
mailing list