0

The following Fortran lines

SUBROUTINE AFprep (ida, idb, jda, jdb, kda, kdb )
  IMPLICIT NONE
  include 'mpif.h'
  USE some_module

    interface
      SUBROUTINE nothing (azf, ata)
        REAL,          INTENT(IN)    :: azf         ( : , : , : )
        REAL,          INTENT(IN)    :: ata         ( : , : , : )
      END SUBROUTINE nothing
    end interface

  REAL,      PARAMETER :: PI = 3.14159265
  REAL( 8 ), PARAMETER :: DPI = 3.14159265358979324D0
  REAL, PARAMETER :: PI180  = PI / 180.0
  REAL, PARAMETER :: GRAV = 9.80622

  INTEGER, INTENT(IN)           :: ida, idb, jda, jdb, kda, kdb
  REAL                          :: aensf

  REAL, ALLOCATABLE, SAVE :: densq   ( : , : , : )

  integer :: i, j, status(MPI_STATUS_SIZE)
  character (len = 50) :: myfmt

END SUBROUTINE AFprep

are producing the error

Error: USE statement at (1) cannot follow INTERFACE statement at (2)

This is bit odd because USE is before interface (unless the compiler moves it around for some reason that I don't see). some_module is a very large module built earlier and the compiler is GCC-11. I'm not really sure what to do because the compilation goes through if USE some_module is commented out (moving USE after interface results in the same error as expected).

  • 1
    Do you have an `interface` statement in `mpif.h`? Do you have an error if you place the USE statement before the INCLUDE line? (The included file probably has many things that cannot come before the USE.) – francescalus Oct 06 '21 at 19:19
  • `mpi.h` is the standard header coming with OpenMPI. I checked and it seems that `mpif-sizeof.h` has its own interface. – afernandezody Oct 06 '21 at 19:29
  • When I move `USE some_module` before `include 'mpi.h` I get the error `USE statement at (1) cannot follow IMPLICIT NONE statement at (2)`. The compilation seems to have gone through once I remove `IMPLICIT NONE` (might have to include `-fimplicit-none` while compiling) – afernandezody Oct 06 '21 at 19:32
  • 3
    IMPLICIT statements [cannot be before](https://stackoverflow.com/a/24337734/3157076) USE statements, yes. Put in the order: USE, IMPLICIT, INCLUDE. – francescalus Oct 06 '21 at 19:33
  • That order also seems to work. Thanks! – afernandezody Oct 06 '21 at 19:43
  • 4
    Regardles of this error, please note that using `use mpi` instead of `include 'mpif.h'` is much better and will allow the compiler to diagnose several kinds of possible bugs. And then there is even the more modern mpi f08 interface, but that requires larger changes. Tje `use mpi` is really just a one line change. – Vladimir F Героям слава Oct 06 '21 at 20:45
  • @Vladimir F. It's not my code and I'm just trying to compile it with minimal changes (the whole thing is tens of thousands of lines) but your advise is noted. Thank you for it! – afernandezody Oct 06 '21 at 20:51

0 Answers0