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

Tobias Burnus burnus at net-b.de
Mon Mar 18 03:44:40 CDT 2013


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



More information about the mpiwg-fortran mailing list