[MPI3 Fortran] Another (smaller) issue with MPI 3.0 and BIND(C)

Bill Long longb at cray.com
Mon Mar 25 16:23:01 CDT 2013



On 3/25/13 1:55 PM, Craig Rasmussen wrote:
> I agree with Tobias.  This also must be changed.

Assuming we have BIND(C) on the Fortran interface, I agree as well. 
Without BIND(C), there is no problem.  (Though the interface to the C 
function would need the fix noted by Tobias, but that appears to be 
outside the scope of the spec).

Cheers,
Bill

>
> I've tried a couple of compilers and they now get sequence association
> correct so that changing the interfaces to arrays of CHARACTER(LEN=1)
> dummy arguments should now work.  A couple of years ago a few compilers
> I tried failed to do this correctly.
>
> Craig Rasmussen
> CAS Scientific Programmer
> rasmus at cas.uoregon.edu <mailto:rasmus at cas.uoregon.edu>
>
>
>
>
> On Mar 18, 2013, at 1:44 AM, Tobias Burnus wrote:
>
>> Dear all,
>>
>> there is possible one other problem with some BIND(C) interfaces in
>> MPI 3.0:
>>
>> MPI_Comm_get_name(comm, comm_name, resultlen, ierror) BIND(C)
>>  TYPE(MPI_Comm), INTENT(IN) :: comm
>>  CHARACTER(LEN=MPI_MAX_OBJECT_NAME), INTENT(OUT) :: comm_nameI
>>
>> Namely, it uses a CHARACTER dummy argument which does not have LEN=1
>> in a procedure with C binding.
>>
>>
>> From Fortran 2008's "15.3.2 Interoperability of intrinsic types"
>> (p.429, paragraph 1):
>>
>> "If the type is character, the length type parameter is interoperable
>> if and only if its value is one."
>>
>>
>> Initially, I though that the following would allow it:
>>
>> "A named scalar Fortran variable is interoperable if and only if its
>> type and type parameters are interoperable, [...] and if it is of type
>> character
>> its length is not assumed or declared by an expression that is not a
>> constant expression."
>> ("15.3.5 Interoperability of scalar variables", p. 432, paragraph 1.)
>>
>> I thought that the latter part allows it. However, as Bill pointed
>> out: The "if and only if ... type parameters are interoperable" makes
>> clear that it is only interoperable if the length is 1. (The second
>> condition makes only sure that this it is compile-time checking by not
>> allowing len=* or nonconst expressions).
>>
>> TS 29113 allows in addtion len=* and len=: for dummy arguments of
>> BIND(C) procedures. However, that doesn't help for
>> LEN=MPI_MAX_OBJECT_NAME, either. (For len=*/len=:, TS 29113 requires
>> that an array descriptor is used; cf. "8.7 Interoperability of
>> procedures and procedure interfaces", p.31, (6)(b) and the paragraph
>> below (6)(d).).
>>
>>
>> I think the simplest is to change:
>>
>>  CHARACTER(LEN=MPI_MAX_OBJECT_NAME), INTENT(OUT) :: comm_nameI
>> to
>>  CHARACTER, INTENT(OUT) :: comm_nameI(MPI_MAX_OBJECT_NAME)
>>
>> Namely, to change the character length to 1 and the array size to
>> MPI_MAX_OBJECT_NAME. Using the storage association for characters, a
>> character(len=MPI_MAX_OBJECT_NAME) variable can be passed to a
>> character(len=1) character array of size MPI_MAX_OBJECT_NAME.
>>
>> To quote the standard:
>>
>> "The type parameter values of the actual argument shall agree with the
>> corresponding ones of the dummy argument that are not assumed, except
>> for the case of the character length parameter of a default character
>> or character with the C character kind (15.2.2) actual argument
>> associated with a dummy argument that is not assumed shape.
>> If a scalar dummy argument is default character or of type character
>> with the C character kind, the length len of the dummy argument shall
>> be less than or equal to the length of the actual argument. The dummy
>> argument becomes associated with the leftmost len characters of the
>> actual argument. If an array dummy argument is default character or of
>> type character with the C character kind and is not assumed shape, it
>> becomes associated with the leftmost characters of the actual argument
>> element sequence (12.5.2.11)."
>>
>> (F2008, "12.5.2.4 Ordinary dummy variables", p. 293, paragraphs 3 and 4.)
>>
>> Tobias
>> _______________________________________________
>> mpi3-fortran mailing list
>> mpi3-fortran at lists.mpi-forum.org <mailto:mpi3-fortran at lists.mpi-forum.org>
>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpi3-fortran
>
>
>
> _______________________________________________
> 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