Fortran submodule file naming
In many applications, a Fortran submodule
is defined in a different file than the Fortran module
that uses it.
Meta-build systems such as CMake and Meson must consider that each Fortran compiler treats Fortran submodule interface file naming distinctively.
Fortran module interface files are like generated header files.
Fortran module files are automatically generated and generally not human-readable.
A brief taxonomy of file naming conventions for Fortran submodules follows. Assume a two-file program:
file basic.f90
module demo
real, parameter :: pi = 4.*atan(1.)
real :: tau
interface
module subroutine hello(pi,tau)
real, intent(in) :: pi
real, intent(out) :: tau
end subroutine hello
end interface
contains
end module demo
program sm
use demo
call hello(pi, tau)
print *,'pi=',pi, 'tau=', tau
end program
file basic_sub.f90
submodule (demo) hi
contains
module procedure hello
tau = 2*pi
end procedure hello
end submodule hi
The order of the commands for each compiler is significant.
The module must be built before the submodule, to generate the necessary module interface files BEFORE compiling the submodule.
Each compiler creates corresponding basic.o
and basic_sub.o
object files.
gfortran -c basic.90
creates files:basic.o demo.mod demo.smod
.gfortran -c basic_sub.f90 -o basic_sub.o
creates files:basic_sub.o demo@hi.smod
.gfortran basic.o basic_sub.o -o basic
creates executablebasic
Here is a table of the module interface files generated by each compiler.
“module” are the files generated by step #1, building the file containing the Fortran module
.
“submodule” are the files generated by step #2, building the containing the Fortran submodule
.
Compiler | module files | submodule files |
---|---|---|
GCC gfortran |
demo.mod demo.smod | demo@hi.smod |
LLVM flang |
demo.mod | demo-hi.mod |
Nvidia HPC nvfortran |
demo.mod | demo-hi.mod |
Intel ifx |
demo.mod | demo@hi.smod |
IBM xlf |
demo.mod | demo_hi.smod |
Cray ftn |
DEMO.mod | HI.mod |
Related:
Fortran submodule reference
Fortran module file format