Ch05 Discussion

Discussion Guide

Warm-up (think–pair–share, 5 min). "You have two arrays of a million numbers to add. In Python you'd write a loop; in Fortran you write c = a + b. Beyond typing less, what has changed?" Surface that the one-liner hands the compiler the whole operation — the seed of the threshold concept.

Main discussion (15–20 min). 1. The memory picture. Put a 3×3 array on the board and ask students to write the order its elements sit in memory. Collect a row-major answer and a column-major answer, then reveal Fortran's choice and ask which loop nest walks memory in order. This is the highest-value ten minutes of the chapter. 2. Elementwise vs matmul. Give A = [[1,2],[3,4]], B = [[5,6],[7,8]] and have half the room compute A * B and half matmul(A, B). Compare. Discuss when each is the operation you actually want (scaling a field vs. a linear transformation). 3. A stencil is a stencil. Show the heat-Laplacian section expression beside the Game-of-Life neighbor sum. Ask what they have in common (shifted copies of the field, summed). Land the idea that every structured-grid simulation is this same shape — the through-line to the capstone.

Group activity (10–12 min). In pairs, take the 10*i + j matrix and, without running anything, predict the printed output of five sections you assign (a row, a column, a strided row, a 2×2 block, and the block's element order). Then have them predict which of two given loop nests over a large array is faster and justify it in one sentence about memory. Collect answers; the block-order and loop-order items are the diagnostic ones.

Exit ticket. "State, in one sentence each: (a) what c = a + b gives the compiler that a loop hides, and (b) which index belongs on the inner loop over a(n,n), and why." Anything that names structure/vectorization for (a) and first index / adjacent memory for (b) is a pass.