[MPI3 Fortran] MPI-2 Fortran question: 2D char arrayin MPI_COMM_SPAWN_MULTIPLE

Jeff Squyres jsquyres at cisco.com
Tue May 25 12:44:56 CDT 2010

On May 25, 2010, at 12:55 PM, Bill Long wrote:

> > The compiler passes the string length as an implicit last argument (or, at last the compilers do that we support in Open MPI). 
> I would expect 2 such hidden arguments at the end of the argument list.
>   The first would be the length of each element of the array
> ARRAY_OF_COMMANDS and the second would be the length of each element of

Sorry -- yes, you are correct.  I was not precise.

> Note that this convention of passing character argument lengths as
> hidden trailing arguments is a vendor implementation convention, but has
> no basis in the language standard.  

Agreed and understood.  If works this way for the compilers that we need to support in OMPI.

> Characters could also, for example,
> be passed as the address of a hidden struct, with the first member of
> the struct being the addresses of the beginning of the string, and the
> second the length.   If the interface specifies BIND(C) then an argument
> if character(1) has to be passed, essentially, as if it were an integer
> with the same number of bits, to match C convention.  Character
> variables with length > 1 are not interoperable, since there is no
> analog in C.

FWIW, I was specifically asking about MPI-2 here, so there's no BIND(C) in the discussion yet.

> > That is, they strategically look for a string_len sized string *comprised of all blanks* to denote the end of the array.
> This would only work if the caller explicitly supplied such a value.

It *seems* to work for all the compilers that I can test, except for gfortran.

Of course, MPI_COMM_SPAWN_MULTIPLE is not a popular routine -- this could well have been broken for years and literally no one has noticed until now.

> And, as noted in a different email, the user also agrees to NOT allow
> any of the other values in the array to be all blanks.    The  user
> instructions on how to use the MPI function need to explicitly say that
> the user has to dimension the array one larger than needed and to insert
> the sentinel value by hand.

It does not currently say this.  This is an implementation artifact that I have seen in 3 implementations (well, 2.5 -- we stole the LAM/MPI code for Open MPI).

> Certainly a compiler would not automatically add in such an extra ending
> sentinel value.  If gfortran did this, someone probably filed a bug and
> had then fix it.  It would be possible, for example,  to have the actual
> argument be in a common block, followed by another character variable in
> the same common block, making the inclusion of an extra pad element in
> the array illegal.


> > Or is the MPI-2 binding for MPI_COMM_SPAWN_MULTIPLE incorrect?
> It is incorrect if it fails to mention that the user is required to
> over-size the array and supply the sentinel value and also make sure
> that no other element of the array is the sentinel value.

The MPI spec does not require this.  I'm only citing how I'm seeing it implemented in 2.5 MPI implementations.  Perhaps other MPI implementations do it differently somehow...?  What does Cray MPI do?

Jeff Squyres
jsquyres at cisco.com
For corporate legal information go to:

More information about the mpiwg-fortran mailing list