N-body bench

bearophile bearophileHUGS at lycos.com
Thu Jan 30 13:04:04 PST 2014


Stanislav Blinov:

> Unrolling everything except the loop in energy() seems to have 
> squeezed the bits neede to outperform c++, at least on my 
> machine :)

That should be impossible, as I remember from my old profilings 
that energy() should use only an irrelevant amount of run time.


> http://dpaste.dzfl.pl/45e98e476daf

While I benchmark some variants of this program I am seeing a 
large variety of problems, limitations, bugs and regressions.

You latest D code crashes my ldc2 V.0.12.1, while 0.13.0-alpha1 
compiles it. My older version of your D code runs with both 
compiler versions, but V.0.12.1 generates faster code.

Plus you can't make those double2 immutable, you can't use vector 
ops (because of performance, and also because they aren't nothrow 
in V.0.12.1).

I was also experimenting with (note the align):

align(16) struct Body {
     double[3] x, v;
     double mass;
}

struct NBodySystem {
private:
     __gshared static Body[5] bodies = [
         // Sun.
         Body([0., 0., 0.],
              [0., 0., 0.],
              solarMass),
...

But this improves the code for V.0.12.1 and worsens it for 
0.13.0-alpha1.


Also I think the __gshared is ignored in V.0.12.1, but this bug 
could be fixed in more recent versions of ldc2.


> (I'm sticking to atoi because my copy of ldc seems to have an 
> issue in std.conv).

My version seems to use to!() correctly.

If ldc2 developers are reading this thread there is enough 
strange stuff here to give one or two headaches :-)

Now I don't know what "final" version should I keep of this 
program :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list