Fortran

On this page 7

Fortran is a compiled, statically typed programming language designed for numerical and scientific computing, with built-in support for multidimensional arrays, complex numbers and parallel execution. Among programming languages, it is the oldest high-level language still in wide professional use, and its name comes from Formula Translation.

Developed by a team at IBM led by John Backus and first released in 1957 for the IBM 704, Fortran proved that a compiler could produce code nearly as fast as hand-written assembly language. Today it is governed by ISO/IEC 1539 and remains central to weather forecasting, climate modeling, computational physics and engineering simulation.

How Fortran achieves high numerical performance

Fortran is fast mainly because its language rules give the compiler freedom to optimize. The standard forbids a procedure from modifying the same memory through two different dummy arguments, so compilers can assume no aliasing and vectorize loops aggressively, something a C compiler can do only when the programmer adds the restrict qualifier.

Arrays are first-class objects with shapes, bounds and whole-array operations. An expression such as c = a + b * 2.0 operates on entire arrays without explicit loops, and the compiler maps it onto SIMD instructions or parallel threads. Arrays are stored in column-major order and indexed from 1 by default, which matters when exchanging data with C or Python.

The table lists the language features that most influence performance.

FeatureWhat it doesPerformance effect
No-aliasing ruleArguments do not overlap in memoryEnables aggressive vectorization
Array syntaxWhole-array and section operationsMaps directly to SIMD hardware
Pure and elemental proceduresFunctions without side effectsSafe parallel execution
DO CONCURRENTLoop with independent iterationsAllows automatic parallelization
CoarraysDistributed arrays across imagesParallel computing without external libraries
Fortran features that support fast numerical code

Fortran standards from FORTRAN 66 to Fortran 2023

Fortran has evolved through a series of formal standards, each largely backward compatible. The spelling changed from FORTRAN to Fortran with the 1990 standard, which also marked the shift from punched-card layout to modern structured programming.

StandardKey additionsPractical significance
FORTRAN 66First ANSI standardPortable code across vendors
FORTRAN 77Character type, block IFDominant legacy dialect
Fortran 90Free-form source, modules, array syntax, allocatable arraysFoundation of modern Fortran
Fortran 95Pure and elemental proceduresCleaner parallel semantics
Fortran 2003Object-oriented features, C interoperabilityMixed-language projects
Fortran 2008Coarrays, DO CONCURRENT, submodulesNative parallel programming
Fortran 2018 and 2023Teams, events, further C integrationIncremental refinement
Major Fortran standards and their key additions

A frequent misconception equates Fortran with fixed-form FORTRAN 77 code. Modern Fortran supports modules, derived types, generic interfaces, polymorphism and standardized interoperability with C through the iso_c_binding module.

Fortran compared with C, C++, Python and MATLAB

Fortran occupies a narrow but deep niche: dense numerical computation where runtime and memory efficiency dominate. The comparison shows where it fits among related languages.

LanguageExecution modelStrength in numericsTypical role
FortranCompiled to native codeNative arrays and strong optimizationSimulation kernels
CCompiled to native codeLow-level control, aliasing limitsSystems and libraries
C++Compiled to native codeTemplates and expression librariesLarge frameworks
PythonInterpretedFast only through compiled librariesWorkflow and analysis
MATLABInterpreted with JITConcise matrix notationPrototyping and teaching
Fortran and related languages in scientific computing

These languages often work together. NumPy and SciPy call Fortran routines from BLAS and LAPACK, the reference linear algebra libraries, and tools such as f2py expose Fortran subroutines directly to Python.

The usual division of labor is therefore pragmatic rather than competitive. Teams prototype and orchestrate in Python or MATLAB, then move the hot loops into Fortran or C++ once profiling shows where time is spent. Rewriting a validated Fortran solver in another language is expensive and risky, because every numerical result must be revalidated against decades of reference cases, so many institutions instead wrap existing Fortran code behind modern interfaces.

Compilers, tools and where Fortran is used

Fortran is supported by actively maintained compilers, including GNU gfortran, Intel ifx, LLVM Flang, NVIDIA nvfortran with GPU offloading, and vendor compilers for supercomputers. Parallelism is added through coarrays, OpenMP directives for shared memory and MPI for distributed clusters.

  • Numerical weather prediction and global climate models run large Fortran code bases on supercomputers.
  • Computational fluid dynamics and structural analysis solvers rely on Fortran kernels.
  • Quantum chemistry and materials science packages are often written mainly in Fortran.
  • High-performance computing benchmarks and national laboratory codes keep Fortran in active development.

Modern tooling includes the Fortran Package Manager (fpm), the community-developed standard library project stdlib, and language servers for code editors.

Limitations and common pitfalls

Fortran is poorly suited to general-purpose application development. Its string handling, user interface options and web ecosystem are weak compared with Python, Java or JavaScript, and the pool of experienced developers is smaller.

PitfallConsequenceRemedy
Missing implicit noneTypos create new variables silentlyDeclare it in every scope
Looping over rows firstPoor cache use in column-major arraysVary the first index fastest
Default real precisionSingle precision rounding errorsUse kind parameters such as real64
Legacy COMMON blocksHidden global stateReplace with module variables
Mismatched C array layoutTransposed or corrupted dataAccount for column-major order
Common Fortran pitfalls and remedies

Maintaining legacy code is the most demanding challenge. Old programs may rely on nonstandard extensions or obsolete constructs, so modernization should proceed incrementally with regression tests that compare numerical results against trusted outputs.

Put simply

Fortran is one of the first programming languages ever created, and it was built for one job: doing large amounts of math very quickly. Scientists use it to tell computers how to predict the weather, simulate air flowing over a wing or model how molecules behave.

It is like a specialized racing car rather than a family vehicle. It is not convenient for everyday tasks such as building websites, but on the numerical racetrack it remains among the fastest.

In practice

A national meteorological service runs a regional weather forecast four times a day on a supercomputer. The atmospheric model, roughly a million lines of modern Fortran, divides the country into a grid of 2.5-kilometer cells and solves the equations of fluid motion for each cell.

The code uses MPI to split the grid across thousands of processor cores and OpenMP within each node. Engineers recently added GPU offloading for the radiation scheme, cutting the runtime of that component by about 60 percent.

The result is a 48-hour forecast delivered within the operational time window of about one hour, while a Python workflow handles data ingestion and the charts published to forecasters.