PHYSICS · Multi-part · Fermi University Physics · Computational Physics · Scientific programming for physicists · High-performance and data-driven computational physics
Scientific Computing for Physicists, Ch Arrays in memory: layout, cost and the data structures of physical problems
Problem
The kinetic energy of N=2×106 identical particles, each of the same known mass m, is computed from their velocities, Ek=21m∑k(vk,x2+vk,y2+vk,z2). Each particle is stored as a record of seven float64 fields, laid out one after another in memory in the order position (x,y,z), velocity (vx,vy,vz), mass m (an array-of-structs layout, which keeps a mass in every record even though here all the masses are equal).
((a)) State how many of the seven fields the kinetic-energy kernel actually needs, and how many bytes per record must come in from main memory when the records lie end to end and are scanned in order, taking 64B cache lines.
((b)) Compute the total bytes read across all particles in this array-of-structs layout.
((c)) If the same data are instead stored as seven separate contiguous arrays, one per field (a struct-of-arrays layout), compute the total bytes the same kernel reads, and give the ratio of the array-of-structs bytes to the struct-of-arrays bytes.