Chapter 16 — Key Takeaways (The Fortran Ecosystem)

A one-page reference to the libraries, the package manager, the standard library, and the tools. Names and roles — the rigorous using of LAPACK is Chapter 21; NetCDF/HDF5 are Chapter 25; MPI is Chapter 34.

The libraries you stand on

Library Does Written in Meet it properly
BLAS vector/matrix kernels (Levels 1/2/3) Fortran (reference); tuned = OpenBLAS, MKL, BLIS Ch. 21, Ch. 29
LAPACK solve $A\mathbf{x}=\mathbf{b}$, eigenvalues, SVD Fortran, on Level-3 BLAS Ch. 21
FFTW fast Fourier transforms C (Fortran interface) spectral methods
NetCDF portable self-describing gridded data C core + netcdf-fortran Ch. 25
HDF5 hierarchical, compressed large output C core + Fortran bindings Ch. 25
MPI message passing across a cluster a standard; MPICH/Open MPI Ch. 34

Reading a LAPACK name: precision · matrix-type · operation

Field Codes
precision S single · D double · C complex · Z double complex
matrix type GE general · SY symmetric · PO sym. pos-def · HE Hermitian · GB banded
operation SV solve · TRF factorize · TRS triangular solve · EV eigen · SVD

Examples: dgesv = double general solve · dsyev = double symmetric eigenvalues · dgesvd = double general SVD · sposv = single positive-definite solve.

The BLAS levels (and why Level 3 is fast)

Level Operates on Data / Flops Speed
1 vector-vector (axpy, dot) $O(n)$ / $O(n)$ memory-bound
2 matrix-vector (gemv) $O(n^2)$ / $O(n^2)$ memory-bound
3 matrix-matrix (gemm) $O(n^2)$ / $O(n^3)$ compute-bound → near peak

Level 3 reuses each loaded number $O(n)$ times (high arithmetic intensity), so a tuned kernel runs near peak. LAPACK is restructured to spend its time in Level-3 calls.

fpm — the Fortran Package Manager

Command Does
fpm new NAME scaffold a project (app/, src/, test/, fpm.toml)
fpm build compile library + apps + tests, in dependency order
fpm run build if needed, run the executable in app/
fpm test build if needed, run the programs in test/

Layout rule: app/ = programs (executables) · src/ = library modules · test/ = tests.

Dependency (git — an inline table, NOT a bare string), pinned for reproducibility:

[dependencies]
stdlib = { git = "https://github.com/fortran-lang/stdlib", tag = "v0.7.0" }

stdlib and the community

  • stdlib — the community standard library: stdlib_stats (mean/var), stdlib_sorting, stdlib_strings, stdlib_io (loadtxt/savetxt), stdlib_math (linspace), stdlib_kinds (dp). A dependency, not part of ISO Fortran — needs fpm to build.
  • fortran-langfortran-lang.org (hub), the Discourse forum, the browser playground (play.fortran-lang.org), and LFortran (LLVM-based, runs Fortran interactively; powers the playground; still maturing — explore/teach with it, build production with an established compiler; more in Ch. 39).

Tooling

Tool Purpose
fortls Language Server — editor autocomplete, go-to-def, live errors (install this first)
FORD HTML docs from !!/!> comments (Ch. 37)
pFUnit unit tests, parallel-capable (NASA Goddard); test-drive = lighter, fpm-native (Ch. 37)
Build systems fpm (new work) · CMake (large/mixed) · Meson · Make (small/legacy) — see Ch. 36
godbolt.org Compiler Explorer — see the assembly gfortran emits (Ch. 27)

Common pitfalls

  • Bare-string git dependency in fpm.toml → fpm reads it as a version, fails. Use { git = "..." }.
  • Missing the Fortran interface of a C library (e.g. netcdf-fortran as well as netcdf-c) → "undefined reference" at link time.
  • Link order for LAPACK: put the source/object before -llapack -lblas on some linkers.
  • Shipping the reference BLAS → correct but slow; install a tuned BLAS for production.
  • Unpinned dependency → your build changes under you; pin a tag for anything reproducible.

Numbers/rules worth memorizing

  • A dense $n\times n$ matrix multiply ≈ $2n^3$ flops (a Level-3 gemm).
  • LAPACK name = precision · matrix-type · operation (e.g. dgesv).
  • fpm layout = app/ programs · src/ library · test/ tests.

The ethic

Call the tuned library; don't hand-optimize. Numerical speed comes from separation of concerns — portable code (LAPACK, yours) on a hardware-tuned kernel (the installed BLAS). You are one person; the library is a career of tuning. (Returns in Ch. 29.)

Project piece added this chapter

The solver becomes an fpm project: fpm new heat-solver, modules into src/, driver into app/, fpm.toml with a stdlib dependency, fpm build / fpm run. One relaxation step on a 3×3 plate (hot top edge = 100) gives u(2,2) = 0.25*(100+0+0+0) = 25.00. Anchor: LAPACK named now; Chapter 21 links it through this same manifest for an implicit step.