Skip to content

Fortran

Fortran has played a central role in meteorology for decades due to its efficiency in numerical computation and array handling. Many legacy and modern weather models, data assimilation systems, and climate simulations are written in Fortran, making it a foundational language for scientific computing in atmospheric sciences. Its performance and portability continue to make it a preferred choice for high-performance computing tasks in meteorology.

Coding

Most often codes are written in Python or Fortran. Here some information is given on Fortran.

Have a look at Debugging

Fortran

Fortran is quite popular in Meteorology and Geophysics. Please find some help on solving common problems.

Get some information on Fortran: - Fortran Language, Learning, Compilers

Compilers

There are a few compilers, but most commonly GNU (Gfortran) and INTEL (ifort) are used on our servers.

GNU Fortran INTEL Fortran
double Fprecision real -fdefault-real-8 -r8
check array bounds -fbounds-check -check
call chain traceback -fbacktrace -traceback
convert little/big endian -fconvert=big-endian/little-endian -convert big_endian/little_endian
default optimisation -O0 -O2
highest recommended optimisation -O3 -O2 maybe -O3 or -fast
position independent code (shared) -fPIC -fPIC

Please take a look into the compiler options guidelines from AMD or Intel, which might be very helpful for finding the right compiler flags for certain CPUs

more information on how to find good options can be found on the PRACE (Partnership for advanced computing in Europe) website

Generating optimized code for a certain processor

All compiler providers have special options that have optimizations for certain processors, especially intel.

Processor Type System Flag (intel) Flag (gcc)
Cascade Lake VSC5 -xCORE-AVX512 -march=cascadelake
Skylake JET, SRVX1, VSC4 -xCORE-AVX512 -march=skylake
Broadwell SRVX8 -xCORE-AVX2 -march=broadwell
Sandy Bridge DEVx1 -xAVX -march=sandybridge
Milan VSC5, Aurora -xCORE-AVX2 -march=znver3
Generic x64 containers -xCORE-AVX2 -march=x86-64-v4

GCC/GFortran processor compiler flags

Intel Compiler

from P. Seibert using ifort for the fastest code (srvx1):

Makefile
1
2
3
4
5
6
# get GRIP_PATH from environment modules
INCPATH = GRIP_API/include
LIBPATH = GRIP_API/lib
# using -xAVX is for old CPUs !!!
FFLAGS = -cpp -xAVX -ipo -O3 -no-prec-div -opt-prefetch  -m64 -mcmodel=medium  -I$(INCPATH)
LDFLAGS = $(FFLAGS) -L$(LIBPATH) -Bstatic -lgrib_api_f90 -lgrib_api -lm -ljasper 

Remark: The above flags and libraries (such as grib_api, jasper, and mcmodel=medium) are specifically needed when compiling FLEXPART, an atmospheric particle dispersion model. For other Fortran projects, these may not be required.
Learn more about FLEXPART here.

Tricky Issues

record markers

On 64-bit machines, some Fortran compilers will insert record markers that are 64-bit integers instead of the standard 32-bit integers.

gfortran man page says:

Text Only
1
2
-frecord-marker=length
Specify the length of record markers for unformatted files. Valid values for length are 4 and 8. Default is 4. This is different from previous versions of gfortran, which specified a default record marker length of 8 on most systems. If you want to read or write files compatible with earlier versions of gfortran, use -frecord-marker=8.

Code Testing

pFUnit - Python Parallel Fortran Unit Testing Framework GitHub

Documentation and other resources

Fortran wikibook DE EN

Automatic Documentation Generation

FORD: Overview in Fortran Wiki | Code on Github