A scalar field is evaluated on a square grid of side

PHYSICS · Subjective · Fermi University Physics · Computational Physics · Scientific programming for physicists · Scientific programming for physicists

Computational Physics, Ch Arrays: a field is a rectangle of numbers

Problem

A scalar field f(x,y)=e−x2−y2f(x,y) = e^{-x^2-y^2} is evaluated on a square grid of side NN, once with a double loop over the two indices and once with the equivalent broadcasting array expression. Each timing below is the smallest of seven repeats from timeit.repeat\texttt{timeit.repeat} on a stated machine:
NNloop timearray time
51510.83 ms0.83\,\mathrm{ms}0.021 ms0.021\,\mathrm{ms}
20120113.2 ms13.2\,\mathrm{ms}0.089 ms0.089\,\mathrm{ms}
801801209 ms209\,\mathrm{ms}1.31 ms1.31\,\mathrm{ms}
200120011310 ms1310\,\mathrm{ms}12.9 ms12.9\,\mathrm{ms}
(a) For each NN, compute the ratio of the loop time to the array time. (b) Compute the loop time and the array time per grid node (i.e. divided by N2N^2), in nanoseconds, at each of the four sizes. (c) State, in one or two sentences, what the per-node figures show about why the ratio rises and then falls, without assuming that a grid size beyond those given behaves the same way.

Browse the problem library