Ch33 Discussion
Discussion Guide
Warm-up (think–pair–share, 5 min). "You run the same compiled program twice, same input, and get two different numbers. What single category of bug is this, and what does it tell you about the code?" (Surfaces: a data race; it tells you a shared variable is being written without synchronization — a scoping mistake.)
Main discussion (15–20 min).
1. Scope every variable. Put the row-normalize loop (Exercise 33.8 / the §33.3 Find-the-Bug) on the board.
Have the class classify every variable's attribute and spot the two that are missing (j, rowsum).
Draw out why each missing one is a race, not just an omission. Reinforce that the outer index is
auto-private but the inner index is not.
2. Reduction vs. the alternatives. Pose: "You need the sum, the max, and a count over a parallel loop. For
each, would you use reduction, atomic, or critical, and why?" Rank by contention. Then ask when a
reduction is impossible (a non-associative combine, appending to a list) and critical is the only tool.
3. Correct but slow. Present the per-thread slot(0:7) array from CS-02 Phase 4. Ask: "This gives the right
answer. Why is it a bug?" Lead to false sharing and the cache line; ask what the fix is (they should reach
for reduction). Ties the performance and correctness halves of the chapter together.
Group activity (10 min). In pairs, give students the serial stencil step and have them add the OpenMP
directive from scratch — deciding, out loud, the attribute of every variable (field, u_new, nx, ny,
rx, ry, i, j) and the schedule. Collect a few; compare to the Project Checkpoint. The point is the
reasoning, not the syntax — they should be able to defend each attribute.
Exit ticket. "Write the one-line directive to correctly sum x(1:n) into s across a team, and state why
the shared-s version is wrong." (Checks reduction(+:s) + the race in one stroke.)