A simulation stores diagnostic data for grid points
PHYSICS · Multi-part · Fermi University Physics · Computational Physics · Scientific programming for physicists · Scientific programming for physicists
Scientific Computing for Physicists, Ch Arrays in memory: layout, cost and the data structures of physical problems
Problem
A simulation stores diagnostic data for 500 grid points, each with 6 field values (density, three velocity components, pressure, temperature), as a NumPy float64 array u of shape (500,6) in C order.
((a)) State the strides of u in bytes.
((b)) A colleague takes u.T without copying any data. State the shape and the strides, in bytes, of this transposed view.
((c)) For u and for u.T, state which axis (first or second) should be the innermost loop of a hand-written kernel to give contiguous memory access, and explain why the answer is not simply "the last axis" for both arrays.