Part VII: Performance

"Premature optimization is the root of all evil… yet we should not pass up our opportunities in that critical 3%." — Donald Knuth

Here is the whole point. You did not choose Fortran for its syntax; you chose it because your computation has to be fast, and Fortran is the language that lets it be. Part VII is where we make good on that promise — carefully, and in the right order. First we understand why Fortran is fast, so that optimization becomes reasoning rather than superstition: the compiler's freedom to optimize, the column-major memory layout you met in Chapter 5, and the no-aliasing guarantee that C spent decades trying to bolt on. Then we measure, because optimizing without measuring is guessing. Then, and only then, we optimize the parts that the measurement says matter.

This part will change how you read your own code. You will come to see a loop and immediately picture how its memory is walked; to reach for a profiler before a hunch; to know which compiler flag buys real speed and which one quietly breaks your numerics. And the running project pays it all back: the heat solver you built in Part V gets profiled, tuned, and rebuilt with aggressive optimization, and you will watch its runtime fall by an order of magnitude — before you have written a single line of parallel code.

What You Will Learn

Chapter 27 — Why Fortran Is Fast. Compiler optimization, column-major access patterns (a 10× difference from loop order alone), the no-aliasing advantage, and how to read an optimization report.

Chapter 28 — Profiling and Benchmarking. Timing with system_clock, profiling with gprof, finding the hot loop, distinguishing memory-bound from compute-bound, and benchmarking honestly.

Chapter 29 — Optimization Techniques. Loop reordering, cache blocking, SIMD vectorization, do concurrent, and knowing when to stop.

Chapter 30 — Compiler Flags. -O2 through -Ofast, -march=native, -flto, the differences between gfortran, Intel, and NVIDIA compilers, and reproducible release builds.

How This Part Fits

Part VII is the payoff of the arrays chapter (Chapter 5) and floating point (Chapter 20), and it is the prerequisite for parallelism: Part VIII assumes you can already make a single core fast, because parallelizing slow serial code just wastes more processors. The Scientist and HPC tracks converge here; no one who cares about speed should skip it.

Time Investment

Chapter Title Difficulty Est. hours
27 Why Fortran Is Fast Advanced 6
28 Profiling and Benchmarking Intermediate 5
29 Optimization Techniques Advanced 6
30 Compiler Flags Intermediate 4
Part VII total ~21 hours

Begin with Chapter 27: not how to make Fortran fast, but why it already is — the understanding that makes every optimization that follows deliberate.

Chapters in This Part