Chapter 16 — Teaching Notes
One-line purpose. Give students the map of the world around the language — the numerical libraries they already stand on, the modern package manager and standard library, and the everyday tooling — so they leave Part III knowing which library to call and which tool to install, and arrive at Ch. 21 already acquainted with LAPACK.
Key ideas to emphasize
- Separation of concerns is the whole game (§16.1, the threshold concept). Portable LAPACK/your code calls a fixed BLAS interface; a swappable, hardware-tuned BLAS supplies the speed. This is why you call tuned libraries instead of hand-optimizing — and it directly sets up "the tuned BLAS beats your loop" in Ch. 29. Do not let it stay abstract: the numpy-overnight-speedup story (Case Study 1, Phase 4) makes it concrete.
- Reading a LAPACK name. precision · matrix-type · operation. Drill it (
dgesv,dsyev,dgesvd,sposv) until the wall of cryptic names becomes legible. It removes the intimidation before Ch. 21. - fpm's convention over configuration (§16.3).
app/programs,src/library,test/tests; declare a git dependency as an inline table andfpm builddoes the rest — including the module compilation order students had to track by hand in Ch. 8. This is the single most useful practical skill in the chapter. - stdlib needs fpm (§16.4). The reason the
code/examples use intrinsics and show stdlib in comments is the same reason a student's firstuse stdlib_statsfails under bare gfortran — the module must be built and linked first. Make this cause-and-effect explicit. - The ecosystem is the "not dead" argument. A package manager, a standard library, a browser playground, a new interactive compiler — built in the open since ~2020. Dead languages do not grow standard libraries.
Misconceptions to preempt
- "LAPACK/BLAS are C or magic." (No — Fortran, and legible once you read the names.)
- "
matmul(or my own loop) is as fast as a tuned BLAS." (No — Ch. 29; the tuned kernel wins.) - "NumPy is faster than Fortran." (NumPy calls Fortran/LAPACK; §16.1 + CS-01.)
- "A git dependency is a bare string in fpm.toml." (No — inline table
{ git = "…" }; Q12 / Ex. 16.13.) - "stdlib is built into the compiler." (No — a package; needs fpm.)
- "FORD comments might break my build." (No — ordinary comments.)
- "FFTW/NetCDF/HDF5 are written in Fortran." (No — C cores with Fortran interfaces; only LAPACK/BLAS reference impls are Fortran. Worth stating precisely; models citation honesty.)
A live demonstration (10 minutes)
At a terminal (or the browser playground if fpm isn't installed): fpm new demo && cd demo && fpm run — show
the "hello" app runs with zero configuration. Then add src/util.f90 with a one-line function, use it from
app/main.f90, and fpm run again — it just works; nobody told fpm about the new file or the dependency.
Then break it: put the dependency in fpm.toml as a bare string URL and show the failure (Ex. 16.13), then
fix it with the inline table. Three minutes of "it just worked" followed by "and here's the one bug everyone
hits" lands both §16.3 and the Find-the-Bug.
Class-time budget (~50 min)
- 12 min: §16.1 — LAPACK/BLAS, the levels, reading names, separation of concerns (the threshold concept).
- 6 min: §16.2 — FFTW/NetCDF/HDF5/MPI as signposts (what each is for; which chapter owns it).
- 12 min: §16.3 — fpm live demo + the manifest + the bare-string bug.
- 8 min: §16.4 — stdlib (why it needs fpm) + the community/playground/LFortran.
- 8 min: §16.5 — fortls (install first), FORD, pFUnit, build-system table.
- 4 min: Project Checkpoint — fpm-ize the solver; the u(2,2)=25 hand check.
Prerequisites to review
Modules and compilation order (Ch. 8) — fpm automates exactly this. Error handling / non-zero exit
(Ch. 13) — needed for the spaced review and for fpm test. A working gfortran (Ch. 2). If possible, have
students install fpm and fortls before class so the demo and Part C exercises land.
Connections
Back: Ch. 5 (matmul/column-major), Ch. 8 (modules), Ch. 13 (error handling), Ch. 15 (Python interop). Forward: Ch. 21 (LAPACK put to work — the anchor payoff), Ch. 25 (NetCDF/HDF5), Ch. 29 (tuned BLAS beats the hand loop), Ch. 34 (MPI), Ch. 36 (build systems in the wild), Ch. 37 (pFUnit/FORD/CI), Ch. 39 (LFortran, stdlib/fpm future). This chapter names all of them; it is the ecosystem hub of the book.