[MPI3 Fortran] Start discussing new Fortran binding

Jeff Squyres jsquyres at cisco.com
Mon Feb 18 16:51:01 CST 2008

On Feb 15, 2008, at 3:56 PM, Craig E. Rasmussen wrote:

>> If I grok this, it looks like the Fortran binding for MPI_COMM_WORLD
>> will always be a C pointer.  How would that translate automatically
>> back to the C bindings if the back-end C type is an integer?  I
>> thought the goal was to make the C and Fortran types be the same (or
>> automatically translatable by the compiler).
>> (note that OMPI uses pointers in C, so ompi_mpi_comm_world is a
>> pointer, not an integer.  But you could s/ompi_mpi_comm_world/
>> mpich_mpi_comm_world/ and have a valid-ish example)
> It would be easier to use ints (as we did in the paper).  I just  
> wasn't
> sure how to implement everything as ints using OpenMPI.  Perhaps you  
> could
> remind me how to do it.

No idea.  :-)

> Ints would be preferable as I've already run into
> trouble with the current implementation attempt (see attached files)  
> as
> the pointers are not compile time constants (and it seems that  
> MPI_Recv is
> messing around with my datatype pointer).

Here's what I see in your MPI_Recv:

     function MPI_Recv(buf, count, datatype, source, tag, comm,  
status) &
              BIND(C, name="MPI_Recv") result(err)
       use, intrinsic :: ISO_C_BINDING
       import MPI_HANDLE_KIND
       implicit none
       type(C_PTR), value, intent(in) :: buf
       integer(C_INT), value, intent(in) :: count
       type(C_PTR), value, intent(in) :: datatype
       integer(C_INT), value, intent(in) :: source
       integer(C_INT), value, intent(in) :: tag
       type(C_PTR), value, intent(in) :: comm
       type(C_PTR), intent(out) :: status
       integer(C_INT) :: err
     end function MPI_Recv

So I think we need to leave it up to the implementation as to what the  
type of the MPI handles are (datatype and comm in this case).  There's  
two cases that I'm aware of:

- the handle is an int in C
- the handle is a pointer in C

Not being a fortran guy, here's a few options that jump to mind (some/ 
all of these make be senseless in Fortran):

1. Can there be a fortran integer equivalent than can map to either of  
those, given an appropriate KIND?

2. Is there a way to use a preprocessor to replace something like this

       integer(MPI_HANDLE_TYPE), value, intent(in) :: datatype

with either C_INT or C_PTR, depending on what the implementation  

3. Does F03 have the equivalent to C's "typedef" such that we could  
create handle types that map to integer(C_INT) or type(C_PTR) (and the  
user doesn't need to know)?

Remember that MPI only has to be source code compatible, not binary  

Sidenote: I don't know why MPI_Recv would modify the value of MPI_INT  
in F03 -- it doesn't on the C side.

Jeff Squyres
Cisco Systems

More information about the mpiwg-fortran mailing list