[Haskell-cafe] Squashing space leaks
Daniel Fischer
daniel.is.fischer at web.de
Fri May 6 17:39:00 EDT 2005
Am Freitag, 6. Mai 2005 16:58 schrieb Greg Buchholz:
> Daniel Fischer wrote:
> > The problem is that a prime crept in in Josef's code,
> > so to calculate the positions and velocities, the updated versions of the
> > planets are used, it should be
>
> Ah, yes, thanks for the correction.
>
> > Besides, offset_momentum does not use the parameter n at all and I think
> > that all the indexing in the computation of the potential energy is
> > rather inefficient.
>
> I wasn't too worried about the energy function, since it only gets
> called twice, whereas the "advance" get called potentially millions of
Of course, and for only five bodies...
> times (and must be the source of the space leak). You can see one
> profile I ran (for n=1000 instead of 1000000) at...
I did profiling for n = 20000 and n = 100000, if I read the profiles
correctly, Josef's code reduces memory usage by a factor of 2 resp. 3, which
ain't bad. Maybe one could reduce space usage further by not creating the
list of iterations but instead make it a tail recursive function? I'll try.
>
> http://sleepingsquirrel.org/nbody/nbody.prof
>
> Thanks,
>
> Greg Buchholz
One question: the energy of the system should be constant - that little
physics I know. What I don't know is whether the change in energy in this
simulation is within usual, reasonable bounds or not. If not, is it due to a
too long time interval or should one use a more sophisticated algorithm?
Cheers,
Daniel
More information about the Haskell-Cafe
mailing list