Related: Gfortran feature set vs. OS and version
For scientists, engineers and other performance-sensitive coders, modern Fortran offers immediate clear advantages. The clarity, conciseness and power of modern Fortran are widely available in contemporary compilers. This brief post was motivated by viewpoints encountered including:
- those whose boss insisted on Fortran 77–they didn’t know anything newer than Fortran 90 existed.
- those who thought essentially no compilers supported newer than Fortran 95 standard (in calendar year 2018).
To be effective with programmer time, one generally shouldn’t needlessly upgrade all Fortran 77 code to modern Fortran, since Fortran has always maintained good backward compatibility. However, new and upgraded Fortran code should almost never be written in Fortran 77 unless specific job conditions dictate. Of course, Fortran 66 / Fortran IV is little supported and will need to be upgraded to Fortran 77 syntax, which is very similar except for file I/O.
New Fortran code should at least use Fortran 2003, which is universally supported by worthwhile compilers. In our work, including in HPC environments, Gfortran and Intel Fortran are widely supported, so we use Fortran 2003, 2008 and 2018 features in virtually every program. We fallback to limited Fortran 2003 feature sets using CMake where strictly necessary.
Modern Fortran support
The compilers easily available supporting modern Fortran include:
- Gfortran 8: Most of Fortran 2008, growing useful subset of Fortran 2018
- Intel Fortran: all of Fortran 2008, growing Fortran 2018 support
- NAG: Fortran 2003 and subset of Fortran 2008
- Flang: Fortran 2003 comprehensive support, growing Fortran 2008
- PGI: Fortran 2003 comprehensive support, growing Fortran 2008 support including
Every year or so, Polyhedral updates their
list of compilers
supporting modern Fortran features, it is a handy reference.
The August 2018 table update did not yet show the Flang compiler, which is advancing beyond the PGI compiler Flang is based on.
For example, Flang supports
submodule whereas PGI did not yet support
What did the major Fortran versions add
- Fortran 95 brought strong N-dimensional array operations. It is a small but important base of modern Fortran, mainly enabling arbitrary size (elemental) intrinsic and non-intrinsic procedures. With Fortran 95, one no longer had to to explicitly loop over almost every array operation.
- Fortran 2003 brought polymorphism and true object-oriented procedures, critical parts of modern generic programming.
- Fortran 2008 strengthened polymorphism, and baked coarray (distributed parallelism) directly into Fortran, transparently using underlying libraries such as OpenMPI.
Improved Fortran software architecture comes through
submoduleenabled by Fortran 2008.
- Fortran 2018 strengthened coarray support, and did further important language cleanup such as enabling