Re: Class Constants - pros and cons
On Wed, 28 Jul 2010, Tom McGlynn wrote:
I'm a little intrigued by the discussion of the appropriate choices for
the architecture for an n-body calculation by a group which likely has
little experience if any in the field.
Direct n-body calculations need to compute the distance between pairs of
objects. The distances between nearby objects need to be calculated
orders of magnitude more frequently than between distant objects. If
the data can be organized such that nearby in [simulated] space stars
tend to be nearby in memory, then cache misses may be substantially
reduced. This can improve performance by an order of magnitude or more.
In Java the only structure you have available that allows for managing
this (since nearby pairs change with time) is a primitive array. Java
gives no way, as far as I know, to manage the memory locations of
distinct objects.
True, although it doesn't prevent cache locality - whereas the parallel
arrays approach immediately rules out locality of the coordinates of a
single star, because they'll be in different arrays. If you want locality,
you'd have to pack the values of all three coordinates into one big array,
which of course is possible.
The dual of the fact that java doesn't let you control locality is that
JVMs are free to control it. There is research going back at least ten
years now into allocation and GC strategies that improve locality. Indeed,
for some popular kinds of collectors, locality is a standard side-effect -
any moving collector where objects are moved in a depth-first traversal of
(some subgraph of) the object graph will tend to put objects shortly after
some other object that refers to them, and thus also close to objects that
are also referred to by that object. It may not help enormously for
mesh-structured object graphs, but it works pretty well for the trees that
are common in real life. If these Stars are held in an octree, for
example, we might expect decent locality.
tom
--
If you're going to print crazy, ridiculous things, you might as well
make them extra crazy. -- Mark Rein