[MPI3 Fortran] [Mpi-comments] MPI 3.0: Fortran 2008 interface - issue with the LOGICAL kind

Bill Long longb at cray.com
Mon Mar 4 13:00:05 CST 2013



On 3/4/13 12:07 PM, N.M. Maclaren wrote:
> On Mar 4 2013, Craig Rasmussen wrote:

>>
>> Nick, can't the wrapper C code safely cast to an integer (or simple
>> assignment after testing for true/false) from a _Bool?
>>
>> To remove BIND(C) from the MPI-3 interfaces is practically very
>> difficult to do because of the PMPI interaces.
>
> I am not sure what you are proposing.  My point is that LOGICAL almost
> certainly will not be interoperable (i.e. is not available in BIND(C)
> interfaces), and that using _Bool VALUE arguments or results is seriously
> problematic, even when moving between two C compilers, let alone a C and
> a Fortran one.

The use of Fortran-C interoperability the way it was intended would have 
specified Fortran interfaces directly for the C library routines, with 
no wrappers needed.  For reasons thought important, the MPI group 
decided to not do that.

The BIND(C) on the wrapper interfaces is not really focused on the 
arguments. It is mainly to define the external name for the subroutine. 
  It is still needed for that, independent of whether there are weird 
arguments with type LOGICAL.   As is the case with default INTEGER, we 
just make believe that the arguments are interoperable.  As a practical 
matter, it does not matter if the wrapper is in Fortran.

>
> There isn't any difficulty about a Fortran wrapper using integers (as
> C does), and converting them to LOGICAL, but it can't be BIND(C).

There is also no difficulty in having the wrapper arguments being LOGICAL.

subroutine sub (x) bind(c, name="MPI_xxx_f")
logical :: x
integer(int) :: cx

cx = merge(1, 0, x)
call mpi_xxx_c (cx)
x = (cx /= 0)

end subroutine sub

>
> A wrapper written in C can't do anything useful, because there are no
> interoperable LOGICAL types except the problematic LOGICAL(C_BOOL).
>

There are numerous reasons for not writing the wrappers in C.  Mainly 
just good code design - C knows nothing about Fortran types. You want 
the parts that depend on particulars of the Fortran typing system to be 
in Fortran.

Cheers,
Bill


>
> Regards,
> Nick Maclaren.
>
>
>
>
>
> _______________________________________________
> mpi3-fortran mailing list
> mpi3-fortran at lists.mpi-forum.org
> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpi3-fortran

-- 
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