0

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?

francescalus
  • 30,576
  • 16
  • 61
  • 96
bob.sacamento
  • 6,283
  • 10
  • 56
  • 115

1 Answers1

1

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.

IanH
  • 21,026
  • 2
  • 37
  • 59
  • Still don't understand the behavior difference, but this clears up a few things. Thanks. Here's a question: Don't think I would ever want to do this in reality, but in principle let's say we take your hypothetical module B and then USE it in module C. And then in module C, we make "something" public again. Will this work? I would expect that public can be turned private, but that once something "in the chain" is private, it couldn't be public again. Thanks for your help. – bob.sacamento Nov 29 '12 at 17:18
  • Module C would then be making public a **different** something - as in module C (assuming it didn't directly use module A) the "something" declared in module A would not be accessible. With implicit typing things would still compile - a problem would only manifest in other code that used both A and C and referenced "something" (the compiler would issue an error about a use name clash). – IanH Nov 29 '12 at 18:49