fortrangfortranpgi

Why does PGI not pick up on public attribute in this module?


Working with someone else's code here. It compiles just fine with gfortran. Under Portland Group, though, I get an error:

pgf90 -DsysLinux -DcompPGF90 -I/home/cables/GITM/share/Library/src  -c  -r8 -fast        ModUtilities.F90
PGF90-S-0084-Illegal use of symbol mpi_wtime - not public entity of module (ModUtilities.F90: 419)
0 inform,   0 warnings,   1 severes, 0 fatal for sleep

The offending line looks like:

use ModMpi, ONLY : MPI_wtime

(There's obviously a lot of MPI stuff going on here, but I don't think that's the point.) So I go to the source code for ModMpi, which is ModMpi.f90, where I see no reference to MPI_WTIME, but I see:

use ModMpiInterfaces

So finally, I go to the source for ModMpiInterface and I find the line:

public:: mpi_wtime

OK, I was able to get a compile from PGI by editing ModMpi.f90 and declaring mpi_wtime to be public. But still, I wonder: Why did gfortran assume (apparently) that mpi_wtime was public, but PGI had to be told this explicitly? Why does PGI not assume that the original public declaration holds throughout the "use chain"?

I presume that one behavior or the other is closer to the Fortran standard. Which would that be?


Solution

  • For exactly the same Fortran source code (as opposed to some sort of MPI library) compiler behaviour should be the same here.

    Whether or not an entity is a public entity of a module is specific to each module that defines or accesses (via USE) that entity. Module A might declare "something" and specify that it is public, module B might USE module A and then specify that same "something" is then private. Any code using module A will be able to access "something", any code only using module B will not.

    The default accessibility of things declared in a module is PUBLIC, but that default can be changed by a PRIVATE statement (one without any following identifiers). If such a private statement appeared, you would see the behaviour you describe with the PGI compiler.

    Implicit typing (i.e. from source code without IMPLICIT NONE) can also confuse things here.