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

Craig Rasmussen rasmus at cas.uoregon.edu
Thu Feb 28 18:16:54 CST 2013


Unfortunately Bill may have a point (though it pains me greatly to admit to this :-).

Tobias' original acceptable possibilities are (with comments):

(a) LOGICAL(C_Bool)

This would require modifying the MPI-3 standard.

(c) Using LOGICAL without BIND(C)

This is attractive from the purely Fortran perspective but it breaks the interface for the MPI tools.

(4d) Last, handling dummy arguments/result variables of BIND(C) procedures differently. That probably would work, but it requires a bunch of the careful addition of additional constraints. For instance, to prohibit the TARGET/POINTER attribute for those.

This would require changes in the Fortran standard.  Who knows if this is possible to accomplish or when it would occur, if at all.

Thus it seems to me that (a) is really the only option.

In general the MPI-3 interfaces were written to make it relatively painless for existing codes to be upgraded.  Thus default INTEGER and default LOGICAL dummy argument types were not changed.  However, it will be necessary for users to change integer handles like MPI_COMM to derived types like TYPE(MPI_COMM).  We could additionally require them to change LOGICAL to LOGICAL(C_Bool).

As I count there are only 31 MPI routines that use LOGICAL arguments.  It doesn't seem too onerous to require programmers to switch to LOGICAL(C_Bool).  We could even provide constants like MPI_TRUE and MPI_FALSE for convenience.

Rolf, I assume you are paying attention to this thread, could you comment?  In particular, what about (evil) users who stuff everything in common blocks.

Craig Rasmussen
CAS Scientific Programmer
rasmus at cas.uoregon.edu




On Feb 28, 2013, at 12:52 PM, Bill Long wrote:

> In C when any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise the result is 1.  (6.3.1.3 Boolean type).
> 
> The value of C_BOOL as a Fortran KIND type for LOGICAL is such that
> 
> 1) The bitsize of LOGICAL(C_BOOL) matches the bitsize of _Bool in C for the companion processor.
> 
> 2) The Fortran processor uses the internal bit pattern in LOGICAL (C_BOOL) of 0 to represent false, and 1 to represent true.
> 
> If both of these is true (which is the case for many implementations) then C_BOOL > 0.  Otherwise C_BOOL will be negative, and there is no interoperability with C for LOGICAL.
> 
> 
> The fatal flaw in the MPI interface here is that the corresponding C formal parameter is not _Bool or anything that looks like LOGICAL. Instead it is 'int'.
> 
> There is no concept of a Fortran argument of type LOGICAL interoperating with a C formal parameter of type int.  Usage of that sort in an MPI interface is simply wrong.  One side or the other of the call needs to be fixed.  I would vote for changing the Fortran side to be type INTEGER(C_INT).
> 
> Cheers,
> Bill
> 
> 
> 
> On 2/28/13 12:29 PM, Craig Rasmussen wrote:
>> 
>> Ack....
>> 
>> I just did a quick rereading of clause 15, Interoperability with C, and
>> it appears ill defined to me.  Consider the following:
>> 
>> 1. Suppose a compiler has a default logical size equivalent to a default
>> integer.  Since the standard only requires one logical kind, this
>> compiler may not have a type that is interoperable with a _Bool C type.
>>  In this instance C_BOOL would be a negative value.
>> 2. If a compiler does support LOGICAL(kind=C_BOOL), what values of a C
>> type _Bool map to .TRUE.?   What values map to .FALSE.?  These mappings
>> may be in clause 15 but I didn't see them at first glance.
>> 3. Suppose a Fortran compiler has the following mapping:
>> 
>>         _Bool flag = 0;      /* flag maps to .FALSE. */
>> 
>>         if (flag != 0)  ...;     /* flag maps to .TRUE. */
>> 
>> This seems to me to be the sane way to map values from C to Fortran.
>>  The same mapping can be done for any C integer type to an equivalently
>> sized Fortran LOGICAL.
>> 
> 
> -- 
> 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
> 
> 
> _______________________________________________
> mpi3-fortran mailing list
> mpi3-fortran at lists.mpi-forum.org
> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpi3-fortran

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpiwg-fortran/attachments/20130228/26ad9ec9/attachment-0001.html>


More information about the mpiwg-fortran mailing list