[MPI3 Fortran] Results of San Jose Forum meeting

Bill Long longb at cray.com
Thu Mar 11 10:13:41 CST 2010

Jeff Squyres wrote:
> On Mar 11, 2010, at 5:28 AM, N.M. Maclaren wrote:

>>> 3. The derived types for MPI handles in "use mpi3" will all be of the
>>> form:
>>>    type MPI_Comm
>>>        sequence
>>>        INTEGER :: val
>>>    end type MPI_Comm
>>>    - This allows the conversion from mpif.h and "use mpi" INTEGER
>>>      handles to "use mpi3" typed handles to be simple assignment --
>>>      there is no need for conversion functions.  Conversion to C
>>>      handles is then already handled by the existing MPI F2C and C2F
>>>      functions.
>> Yuck.  You're not planning on playing tricks with EQUIVALENCE, are you?
>> If not, why a sequence type?
> I don't know what EQUIVALENCE is; there was no mention of it in the discussion.
> Rolf explained the SEQUENCE as meaning that this would guarantee that an instance of the derived type in memory would be exactly the same as a single INTEGER.

I think this is only ensured if the type is a bind(c) type.  If you use

type,bind(c) :: MPI_Comm
     integer(c_int) :: val
end type MPI_Comm

which corresponds to a C structure with one member of type int. The C 
standard requires that "A pointer to a structure object, suitable 
converted, points to its initial member ...".  Unnamed padding at the 
beginning of a C struct is prohibited.  And Fortran is required to 
follow the C rules for layout of a bind(c) type. So, if something like 
this is passed by address, then the address of the struct and the 
address of the integer will be the same, and you get your "same memory 
layout" requirement satisfied.  You also have something that can be 
legally passed to a C routine.


Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101

More information about the mpiwg-fortran mailing list