Ch04 Discussion

Discussion Guide

Warm-up (think–pair–share, 5 min). Put do concurrent (i = 1:n) y(i) = y(i-1) + 1 end do on the board: "Is this valid? Why or why not?" Surfaces the independence promise immediately and productively (it is invalid — a loop-carried dependency).

Main discussion (15–20 min). 1. Right loop for the job. Give three tasks — "sum 1..100", "iterate until the residual < 1e-6", "read numbers until end-of-file" — and have the class pick counted / do while / infinite-do+exit for each, defending the choice. (Answers: counted; do while or infinite+exit; infinite+exit.) 2. The footgun tour. List C's switch fall-through and the real == trap. Ask: "What did Fortran's designers give up to remove each, and was it worth it?" Teaches that safety-vs-flexibility is a design decision, not an accident. 3. When is do concurrent a lie? Have pairs invent one loop that is safe for do concurrent and one that is not, and state the rule that distinguishes them (does any iteration read what another writes?).

Group activity (10 min). In pairs, students take the Project Checkpoint skeleton and, on paper, predict the boundary=/interior= counts for a 6×4 grid before editing the code (answer: 24 total, interior i∈{2..5}×j∈{2,3} = 4×2 = 8, boundary = 16). Then they change nx,ny and confirm. Reinforces the boundary-vs-interior if that Chapter 24 will fill with physics.

Exit ticket. "Write the exit condition for a loop that stops when a real x is 'close enough' to 1.0, and say why you did not write x == 1.0." (Checks the §4.1 real-equality discipline; anything using a tolerance abs(x - 1.0_dp) < tol is a pass.)