As usual, 'it depends', but a struct of arrays layout (which is a virtual necessity on GPU's), can also be advantageous on the CPU. One rarely acts on only a single object at a time; but quite often, you only work on a subset of the objects attributes at a time. In an array of structs layout, you are always pulling the whole objects from main memory into the cache, even if you only use a single attribute. In a struct of arrays layout, we can do efficient prefetching on a single attribute when looping over all objects.
On Thu, Feb 13, 2014 at 3:37 PM, Sturla Molden <sturla.mol...@gmail.com>wrote: > Neal Becker <ndbeck...@gmail.com> wrote: > > I thought this was interesting: > > > > http://www.libgeodecomp.org/libflatarray.html > > This is mostly flawed thinking. Nowadays, CPUs are much faster than memory > access, and the gap is just increasing. In addition, CPUs have hierarchical > memory (several layers of cache). Most algorithms therefore benefit from > doing as much computation on the data as possible, before reading more data > from RAM. That means that an interleaved memory layout is usually the more > effective. This of course deepends on the algorithm, but an array of > structs is usually better than a struct of arrays. > > Sturla > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion