[MPI3 Fortran] Default integers open for discussion

Lionel, Steve steve.lionel at intel.com
Wed Sep 2 12:30:59 CDT 2009


Craig wrote:

> I've been back and forth on this (as well as a few others I think).   
> I'm currently leaning toward using default integers.  Primarily  
> because to do otherwise could potentially break countless lines of  
> users code.  

No, it won't, as long as the choice for the MPI integer kind matches C_INT, which is pretty much universal for default integer in Fortran implementations.  

Let me try an example.

module MPI
use, intrinsic :: ISO_C_BINDING
integer, parameter :: MPI_INT_KIND = C_INT

interface
subroutine MPI_SUB (INTARG)
import ! Makes the definition of MPI_INT_KIND visible here
integer(MPI_INT_KIND), intent(IN) :: INTARG
end subroutine MPI_SUB
end module MPI


User code:

program test1
use MPI
integer SOMEVAR1
call MPI_SUB (SOMEVAR1)
end

This is the "existing code" case.  The compiler will have a kind for "default integer" - the number chosen for this kind value varies by implementation (usually 4 but not always) - let's say it's 4 here.  For this combination of Fortran and a "companion C processor", C_INT is also 4, and thus so is MPI_INT_KIND.  The declaration of SOMEVAR1 does not specify a kind, so it gets "default integer" or 4.  No problem yet.

Now let's say that this user has decided to compile her Fortran code with an option that changes the default integer kind to 8 (-i8 or similar).  Now if the above code is compiled, there will be an error because the module, assuming it wasn't also compiled -i8, defines the argument as INTEGER(4) but SOMEVAR1 is now INTEGER(8).  The user may have had a reason to use -i8 for other variables and now needs to figure out what to do.  She reads the source of the MPI module, but if it just says INTEGER with no KIND value, she may be at a loss to figure out what to change. 

If it had been written like this:

program test2
use MPI
integer(MPI_INT_KIND) SOMEVAR2
call MPI_SUB (SOMEVAR2)
end

The call with SOMEVAR2 is ok in either case, because the explicit kind overrides the default integer kind in effect.

Explicitly specifying the KIND value in the module helps documentation and encourages, but does not require, the programmer to specify the KIND value in their own code.  It does no harm and does not force coding changes that wouldn't be needed otherwise.  Using explicit kinds also helps make the code understandable.

Regarding functions and subroutines, I think I would need a bit more background on the earlier discussion. I'll be glad to help on this and perhaps a phone call with you and Jeff would be in order when convenient.


Steve Lionel
Intel Developer Support
Nashua, NH







More information about the mpiwg-fortran mailing list