Ch15 Discussion

Discussion Guide

Warm-up (think–pair–share, 5 min). "You profiled your Python simulation: 95% of the time is in one loop. What are your options, and which would you pick?" Surfaces the whole-vs-hot-loop insight before you name it.

Main discussion (15–20 min). 1. Where's the boundary? Put the two-language table on the board. Have the class sort tasks (read config, FFT a signal, draw a figure, sweep a stencil, decide when to stop) into Python-side vs Fortran-side, and defend the borderline ones. Teaches the §15.1 judgment. 2. The copy that eats the speedup. Present the Find-the-Bug from §15.3 (C-contiguous 2000×2000 called 50,000 times). Ask them to estimate the bytes copied, then produce the one-keyword fix. This makes the order='F' idea visceral and quantitative. 3. How fast, honestly? Ask: "Is it fair for a textbook to print 'this is 50× faster'?" Use it to teach why the book gives an order of magnitude and asks them to measure — and why assert np.allclose guards the claim. Ties honesty-of-claim (a book-wide value) to benchmarking.

Group activity (12 min). In pairs, students take code/example-01-sum-squares.f90, wrap it, and call it from Python — then modify it to also return the mean (a second intent(out)) and predict how the Python return value changes before rebuilding. Whoever finishes early: make the array 2-D and break it on purpose by omitting order='F', then fix it. Collect one pair's "what surprised you."

Exit ticket. "In one sentence each: (a) what does order='F' prevent, and (b) why is the pure-Python loop slow even though it does the same arithmetic?" (Checks the two load-bearing ideas: the boundary copy, and interpreter overhead. Anything reasonable about 'avoids the copy' and 'per-element interpreter overhead' is a pass.)