Affiliate disclosure
Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.
Chapter 30 — Further Reading
The flags in this chapter are documented most authoritatively by the compiler vendors themselves, and
understood most deeply through the floating-point theory that -Ofast puts at risk. The list below is
deliberately short and practical: the pages you will actually open while tuning a build.
The compiler manuals (primary sources — keep these bookmarked)
- The GCC manual, "Options That Control Optimization" (gcc.gnu.org/onlinedocs). The definitive
reference for
-O0…-Ofast,-march,-flto,-ffast-math, and every sub-flag they imply. When you need to know exactly what a flag does on your version, this is the source of truth — and the composition of-Ofastand-ffast-mathis spelled out here, sub-flag by sub-flag. - The GNU Fortran (gfortran) manual (gcc.gnu.org/onlinedocs/gfortran). The Fortran-specific flags —
-fcheck=all,-fbacktrace,-ffpe-trap,-fno-protect-parens,-finit-real— and their exact semantics. Read the "Error and Warning Options" and "Code Gen Options" sections. - Intel oneAPI Fortran (
ifx) Developer Guide and Reference (intel.com). The authority for-xHost,-ipo,-qopt-report, and — crucially — the-fp-modelsettings and their defaults, which are the single most common source of cross-compiler result differences. - NVIDIA HPC SDK documentation (docs.nvidia.com/hpc-sdk). The
nvfortranreference:-fast,-Minfo, and the OpenACC/CUDA-Fortran flags you will meet again in Chapter 35.
Floating point — why -Ofast is dangerous (read before you use it)
- David Goldberg, "What Every Computer Scientist Should Know About Floating-Point Arithmetic,"
ACM Computing Surveys, 1991. The classic. It explains non-associativity, rounding, and cancellation —
precisely the properties
-ffast-mathtrades away. If §30.1's1.0-becomes-0.0example unsettled you, this paper is why. - The GCC wiki page on floating-point math and
-ffast-math(gcc.gnu.org/wiki). A practical companion to Goldberg: what each-ffast-mathsub-optimization assumes about your program, and how each can bite. - Chapter 20 of this book (Floating Point). The in-house treatment; re-read §20 on machine epsilon and catastrophic cancellation alongside this chapter.
Optimization in depth
- Agner Fog's optimization manuals and instruction tables (agner.org). Deep, practitioner-grade material
on how modern CPUs execute code — SIMD widths, FMA, and why
-march=nativehelps some loops and not others. Tier 2, but among the most respected free resources in the field. - Metcalf, Reid & Cohen, Modern Fortran Explained (Oxford University Press). The standard-focused
reference; its treatment of
iso_fortran_envcoverscompiler_version()andcompiler_options(), the reproducibility tools of §30.4. fortran-lang.org— the community "best practices" and compiler pages, including a maintained comparison of the free and commercial Fortran compilers and their flags.
Tools
- Compiler Explorer / Godbolt (godbolt.org). Paste a Fortran routine, choose a compiler and flags, and
see the assembly — the fastest way to confirm that
-O3 -march=nativeactually vectorized your loop, or that-Ofastreassociated your sum. Indispensable for understanding what a flag really did. fpm(Fortran Package Manager) (fpm.fortran-lang.org). Build profiles (--profile release/debug) that make the two-build discipline of §30.3 automatic and portable across compilers — the practical home for the profile table of Case Study 30.2.
Appendix and cross-references
- Appendix C: gfortran Setup and Compiler Flags. The book's consolidated flag table — development, optimization, parallel, and library-linking flags in one place. This chapter was the narrative; the appendix is the lookup.
- Chapter 28: Profiling and Benchmarking for the timing methodology every flag comparison in this chapter assumes, and Chapter 37: Testing and Documentation for reproducibility as engineering discipline.
Suggested order
- Skim the GCC "Options That Control Optimization" page — just the
-Olevels and-Ofast. - Read Goldberg (or re-read Chapter 20) enough to respect
-ffast-mathbefore you ever type it. - Try a loop in Godbolt at
-O2,-O3, and-O3 -march=native; watch the vectorization appear. - Read the Intel
-fp-modelsection — the one cross-compiler gotcha most likely to bite you. - Keep Appendix C open the next time you build anything.