Ch28 Discussion
Discussion Guide
Opening prompt (5 min). "You have one week to make a 100,000-line simulation faster. What is the very first thing you do?" Surface answers before revealing "profile." Most students name a code change; the point is that the first move is a measurement, not an edit. Tie to Pike's Rule 1.
Discussion questions:
1. Why is human intuition about where time goes so reliably wrong? What is it about a large program that
defeats guessing? (Draw out: hot loops hide in library calls, in $O(n^2)$ inner loops, in surprising
places; the code you wrote is not the code that runs after inlining.)
2. cpu_time and system_clock measure different things. Give a real scenario where each of the three
relationships (wall ≈ CPU, wall ≫ CPU, CPU > wall) tells you something actionable before you profile.
3. The stencil is memory-bound; a tuned dgemm is compute-bound. Both are "just loops doing arithmetic on
arrays." What makes one starved for data and the other saturated with it? (Draw out: arithmetic intensity
= data reuse; blocking raises reuse. Connect forward to Ch. 29 and back to Ch. 21.)
4. Every timing number in this chapter is labelled "representative." Is that a weakness of the book or a
lesson about performance? When is a reported benchmark number trustworthy, and what must accompany it?
(Draw out: reproducibility — flags, machine, statistic, spread; Ch. 37.)
5. The 80/20 rule says the prize is in one loop. When is that assumption false, and how would the flat
profile look (four routines at 25% each)? What does a "flat" flat profile imply about your optimization
strategy — and about the code's design?
Mini group activity (20 min): "Where's the prize?" Hand each group the representative flat profile from §28.2 (laplacian 78%, step 17%, MAIN 5%). Each group computes, for every routine, the maximum whole-program speedup from making that one infinitely fast ($S = 1/(1-p)$), and the speedup from making it exactly $2\times$ faster ($S = 1/((1-p)+p/2)$). Fill a shared board:
| Routine | share $p$ | ceiling $1/(1-p)$ | with $2\times$ |
|---|---|---|---|
| laplacian | 0.78 | ? | ? |
| step | 0.17 | ? | ? |
| MAIN | 0.05 | ? | ? |
They discover laplacian's ceiling is ~4.5× and even a modest 2× on it beats infinitely fast on the other two combined. Debrief on the lesson: the profiler tells you where the time is, and this arithmetic tells you whether the effort is worth it — you compute the size of the prize before you pay for it. This makes the 80/20 rule quantitative and hand-owned in twenty minutes.