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

Craig Rasmussen rasmus at cas.uoregon.edu
Mon Mar 25 13:55:31 CDT 2013


I agree with Tobias.  This also must be changed.

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




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
> 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/20130325/f2b2a9e8/attachment-0001.html>


More information about the mpiwg-fortran mailing list