Ch27 Discussion

Discussion Guide

Prompts

  1. "You don't make Fortran fast — the compiler does." Defend or refute. If the compiler does the work, what exactly is left for the programmer, and why is it still decisive? (Aim: loop order, non-aliasing, purity, and knowing which loop to hand to a library.)
  2. The no-aliasing advantage is "a gift with a contract." State the gift and state the contract. Construct a scenario where a programmer enjoys the gift while unknowingly breaking the contract, and describe how the bug would manifest (and why it is so hard to find).
  3. Fortran guarantees non-aliasing by default; C makes you request it with restrict. Is Fortran's approach strictly better, or is there a real cost to forbidding aliasing? What kind of program wants pointers that may alias, and why is that C's domain, not Fortran's?
  4. A loop is "fully vectorized" per the report, yet barely faster than the scalar version. Explain how both can be true. What one number would you compute to have predicted it, and what would you optimize instead?
  5. When is it right to stop optimizing a loop yourself and call a tuned library (dgemm) instead? Phrase a rule a junior engineer could apply. (Tie to arithmetic intensity and Ch. 21.)

Mini group activity (≈ 25 min). In pairs, hand each pair a different kernel written to fail exactly one of Case Study 2's four design goals (rotate among: arrays aliased as in/out; a print/counter side effect in the inner loop; loops nested inside-out; a pointer-based version with no contiguous). Each pair must (a) predict, before compiling, which goal is broken and what -fopt-info-vec-missed will say; (b) compile and confirm the compiler's complaint; (c) fix the one goal and confirm the loop now vectorizes. Then pairs swap kernels. Close by building, on the board, a "broken goal → compiler complaint → fix" table — the diagnostic Rosetta Stone from CS-02 Option B. The learning outcome: the four design goals are not style — each removes a specific reason the compiler refuses to go fast, and the report names which.