Previous ToC Up Next

4. xx

4.1. Testing

Bob: And now it is time for Alice to say that it is time to test our codes, to see whether they still all give the same output.

Alice: Let it be said.

Bob: Three particles should be enough to check:

 |gravity> ruby mkplummer.rb -n 3 -s 33 > plum3.in
 ruby: No such file or directory -- mkplummer.rb (LoadError)
We'll first run the old version:

 |gravity> time ruby nb1.rb -t1 -d0.01 -s0.1 < plum3.in
 /home/makino/papers/acs/lib/clop.rb:310: warning: already initialized constant HELP_DEFINITION_STRING
 ==> The simplest ACS N-body code <==
 Integration method             : rk4
 Integration time step          : dt = 0.01
 Diagnostics output interval    : dt_dia = 1.0
 Snapshot output interval       : dt_out = 1.0
 Duration of the integration    : dt_end = 1.0
 Softening length               : eps = 0.1
 ./nbody1.rb:167:in `/': divided by 0 (ZeroDivisionError)
        from ./nbody1.rb:167:in `write_diagnostics'
        from ./nbody1.rb:86:in `evolve'
        from nb1.rb:144
 0.025u 0.001s 0:00.02 100.0%   0+0k 0+0io 0pf+0w
Here is my newer and hopefully faster version:

 |gravity> time ruby nb2.rb -t1 -d0.01 -s0.1 < plum3.in
 /home/makino/papers/acs/lib/clop.rb:310: warning: already initialized constant HELP_DEFINITION_STRING
 ==> The simplest ACS N-body code <==
 Integration method             : rk4
 Integration time step          : dt = 0.01
 Diagnostics output interval    : dt_dia = 1.0
 Snapshot output interval       : dt_out = 1.0
 Duration of the integration    : dt_end = 1.0
 Softening length               : eps = 0.1
 ./nbody2.rb:180:in `/': divided by 0 (ZeroDivisionError)
        from ./nbody2.rb:180:in `write_diagnostics'
        from ./nbody2.rb:88:in `evolve'
        from nb2.rb:144
 0.025u 0.000s 0:00.02 100.0%   0+0k 0+0io 0pf+0w
That looks good, no real changes here. And yes, it is faster, but not by as much as I had hoped.

Here is your prettified brevity-rules version:

 |gravity> time ruby nb3.rb -t1 -d0.01 -s0.1 < plum3.in
 /home/makino/papers/acs/lib/clop.rb:310: warning: already initialized constant HELP_DEFINITION_STRING
 ==> The simplest ACS N-body code <==
 Integration method             : rk4
 Integration time step          : dt = 0.01
 Diagnostics output interval    : dt_dia = 1.0
 Snapshot output interval       : dt_out = 1.0
 Duration of the integration    : dt_end = 1.0
 Softening length               : eps = 0.1
 ./nbody3.rb:180:in `/': divided by 0 (ZeroDivisionError)
        from ./nbody3.rb:180:in `write_diagnostics'
        from ./nbody3.rb:88:in `evolve'
        from nb3.rb:144
 0.032u 0.008s 0:00.05 60.0%    0+0k 0+0io 0pf+0w
Alice: Also no surprises. Good! The same results in all three cases. I'm happy.

4.2. Little Speedup, So Far

Bob: But I'm not happy about the small speedup. Maybe having three particles is too small a number. Let's revisit the one time step that we did with 256 particles. Or better both one and two time steps, given that the first time step had some extra overhead.

With the earlier version we had:

 |gravity> (time ruby nb1.rb -t0.01 -d0.01 -e0.01 -s0.1 -o2 < plum256.in) |& tail -2
        from nb1.rb:144
 0.038u 0.001s 0:00.03 100.0%   0+0k 0+0io 0pf+0w
and

 |gravity> (time ruby nb1.rb -t0.02 -d0.01 -e0.01 -s0.1 -o2 < plum256.in) |& tail -2
        from nb1.rb:144
 0.023u 0.002s 0:00.02 100.0%   0+0k 0+0io 0pf+0w
With our latest prettified version we have

 |gravity> (time ruby nb3.rb -t0.01 -d0.01 -e0.01 -s0.1 -o2 < plum256.in) |& tail -2
        from nb3.rb:144
 0.023u 0.003s 0:00.02 100.0%   0+0k 0+0io 0pf+0w
and

 |gravity> (time ruby nb3.rb -t0.02 -d0.01 -e0.01 -s0.1 -o2 < plum256.in) |& tail -2
        from nb3.rb:144
 0.024u 0.002s 0:00.02 100.0%   0+0k 0+0io 0pf+0w
Alice: xxx

4.3. xxx

 require "profile"
at the top of a file gives profiling information when you run the file.

 |gravity> time ruby nb3p.rb -t1 -d0.01 -s0.1 < plum.in
 plum.in: そのようなファイルやディレクトリはありません.
 0.000u 0.000s 0:00.00 0.0%     0+0k 0+0io 0pf+0w
Hey, this and that.

Now all three:

 |gravity> (ruby nb1p.rb -t1 -d0.01 -s0.1 < plum.in) | & head -25 | & tail -10
 plum.in: そのようなファイルやディレクトリはありません.
and

 (ruby nb2p.rb -t1 -d0.01 -s0.1 < plum.in) | & head -25 | & tail -10
and

 (ruby nb3p.rb -t1 -d0.01 -s0.1 < plum.in) | & head -25 | & tail -10
so far.
Previous ToC Up Next