performance measurements

Each table row shows performance measurements for this C# Mono program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,000Failed  1461   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read n-body benchmark to see what this program should do.

 notes

Mono JIT compiler version 3.4.1 (master/1b936ba Mon Apr 28 16:16:26 PDT 2014)
LLVM: yes(3.4svn-mono-mono/e656cac)
GC: sgen

 n-body C# Mono #4 program source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   contributed by Isaac Gouy, optimization and use of more C# idioms by Robert F. Tobler
   simdified by Konrad M. Kruczynski and Jaroslaw M. Gliwinski
*/
using System;
using Mono.Simd;

namespace NBody
{
   class NBody
   {
      public static void Main(String[] args)
      {
         var n = args.Length > 0 ? Int32.Parse(args[0]) : 10000;
         var bodies = new NBodySystem();
         var dtdt = new Vector2d(0.01);
         Console.WriteLine("{0:f9}", bodies.Energy());
         for (var i = 0; i < n; i++) bodies.Advance(ref dtdt);
         Console.WriteLine("{0:f9}", bodies.Energy());
      }
   }

   class Body
   {
      public Vector2d Pxy;
      public Vector2d Pz0;
      public Vector2d Vxy;
      public Vector2d Vz0;
      public Vector2d MassMass;

   }

   class Pair
   {
      public Body Bi, Bj;
   }

   class NBodySystem
   {
      private readonly Body[] bodies;
      private readonly Pair[] pairs;

      const double Pi = 3.141592653589793;
      const double SolarMass = 4 * Pi * Pi;
      const double DaysPerYear = 365.24;

      public NBodySystem()
      {
         bodies = new[] {
                        new Body
                           { // Sun
                              MassMass = new Vector2d(SolarMass, SolarMass)
                           },
                        new Body
                           { // Jupiter
                              Pxy = new Vector2d(4.84143144246472090e+00, -1.16032004402742839e+00),
                              Pz0 = new Vector2d( -1.03622044471123109e-01, 0),
                              Vxy = new Vector2d(1.66007664274403694e-03 * DaysPerYear,  7.69901118419740425e-03 * DaysPerYear),
                              Vz0 = new Vector2d(-6.90460016972063023e-05 * DaysPerYear, 0),
                              MassMass = new Vector2d(9.54791938424326609e-04 * SolarMass)
                           },
                        new Body
                           { // Saturn
                              Pxy = new Vector2d(8.34336671824457987e+00, 4.12479856412430479e+00),
                              Pz0 = new Vector2d(-4.03523417114321381e-01, 0),
                              Vxy = new Vector2d(-2.76742510726862411e-03 * DaysPerYear, 4.99852801234917238e-03 * DaysPerYear),
                              Vz0 = new Vector2d(2.30417297573763929e-05 * DaysPerYear, 0),
                              MassMass = new Vector2d(2.85885980666130812e-04 * SolarMass)
                           },
                        new Body
                           { // Uranus
                              Pxy = new Vector2d(1.28943695621391310e+01, -1.51111514016986312e+01),
                              Pz0 = new Vector2d(-2.23307578892655734e-01, 0),
                              Vxy = new Vector2d(2.96460137564761618e-03 * DaysPerYear, 2.37847173959480950e-03 * DaysPerYear),
                              Vz0 = new Vector2d(-2.96589568540237556e-05 * DaysPerYear, 0),
                              MassMass = new Vector2d(4.36624404335156298e-05 * SolarMass)
                           },
                        new Body
                           { // Neptune
                              Pxy = new Vector2d(1.53796971148509165e+01, -2.59193146099879641e+01),
                              Pz0 = new Vector2d(1.79258772950371181e-01, 0),
                              Vxy = new Vector2d(2.68067772490389322e-03 * DaysPerYear, 1.62824170038242295e-03 * DaysPerYear),
                              Vz0 = new Vector2d(-9.51592254519715870e-05 * DaysPerYear, 0),
                              MassMass = new Vector2d(5.15138902046611451e-05 * SolarMass)
                           },
                     };

         pairs = new Pair[bodies.Length * (bodies.Length - 1) / 2];
         var pi = 0;
         for (var i = 0; i < bodies.Length - 1; i++)
         {
            for (var j = i + 1; j < bodies.Length; j++)
            {
               pairs[pi++] = new Pair { Bi = bodies[i], Bj = bodies[j] };
            }
         }

         var pxy = new Vector2d(0);
         var pz0 = new Vector2d(0);
         for (var i = 0; i < bodies.Length; i++ )
         {
            var b = bodies[i];
            pxy += b.Vxy * b.MassMass;
            pz0 += b.Vz0 * b.MassMass;
         }
         var sol = bodies[0];
         var minusOne = new Vector2d(-1);
         var solarMass = new Vector2d(SolarMass);
         sol.Vxy = minusOne * pxy / solarMass;
         sol.Vz0 = minusOne * pz0 / solarMass;
      }

      public void Advance(ref Vector2d dtdt)
      {
         foreach (var p in pairs)
         {
            var bi = p.Bi;
            var bj = p.Bj;
            var dxdy = bi.Pxy - bj.Pxy;
            var dzd0 = bi.Pz0 - bj.Pz0;
            var distvec = (dxdy * dxdy).HorizontalAdd(dzd0 * dzd0);
            var d2 = distvec.HorizontalAdd(distvec);
            var mag = dtdt / (d2.Sqrt() * d2);
            bi.Vxy -= dxdy * bj.MassMass * mag;
            bj.Vxy += dxdy * bi.MassMass * mag;
            bi.Vz0 -= dzd0 * bj.MassMass * mag;
            bj.Vz0 += dzd0 * bi.MassMass * mag;
         }
         foreach(var b in bodies)
         {
            b.Pxy += dtdt * b.Vxy;
            b.Pz0 += dtdt * b.Vz0;
         }
         
      }

      public double Energy()
      {
         var half = new Vector2d(0.5);
         var e = new Vector2d(0.0);
         for (var i = 0; i < bodies.Length; i++)
         {
            var bi = bodies[i];
            var sq = (bi.Vxy*bi.Vxy).HorizontalAdd(bi.Vz0*bi.Vz0);
            e += half * bi.MassMass * sq.HorizontalAdd(sq);
            for (var j = i + 1; j < bodies.Length; j++)
            {
               var bj = bodies[j];
               var dxdy = bi.Pxy - bj.Pxy;
               var dzd0 = bi.Pz0 - bj.Pz0;
               var sqvec = (dxdy * dxdy).HorizontalAdd(dzd0 * dzd0);
               e -= (bi.MassMass * bj.MassMass) / (sqvec.HorizontalAdd(sqvec)).Sqrt();
            }
         }
         return e.X;
      }
   }
}

 make, command-line, and program output logs

Tue, 29 Apr 2014 05:12:28 GMT

MAKE:
mv nbody.csharp-4.csharp nbody.csharp-4.cs
/usr/local/bin/mcs -r:/usr/local/lib/mono/4.5/Mono.Simd.dll -optimize+ -platform:x86 -out:nbody.csharp-4.csharp_run nbody.csharp-4.cs
rm nbody.csharp-4.cs
0.22s to complete and log all make actions

COMMAND LINE:
/usr/local/bin/mono --llvm --gc=sgen nbody.csharp-4.csharp_run 500000

PROGRAM FAILED 


PROGRAM OUTPUT:

mono: /usr/local/src/llvm/include/llvm/ADT/SmallVector.h:144: const T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](unsigned int) const [with T = unsigned int; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = const unsigned int&]: Assertion `begin() + idx < end()' failed.
Stacktrace:

  at <unknown> <0xffffffff>
  at NBody.NBody.Main (string[]) <0x00043>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	/usr/local/bin/mono() [0x8164eaa]
	[0xb770240c]
	[0xb7702424]
	/lib/i386-linux-gnu/libc.so.6(gsignal+0x47) [0xb73ca827]
	/lib/i386-linux-gnu/libc.so.6(abort+0x143) [0xb73cdc53]
	/lib/i386-linux-gnu/libc.so.6(+0x27977) [0xb73c3977]
	/lib/i386-linux-gnu/libc.so.6(+0x27a27) [0xb73c3a27]
	/usr/local/bin/mono() [0x85b702f]
	/usr/local/bin/mono() [0x830e26a]
	/usr/local/bin/mono() [0x830f49b]
	/usr/local/bin/mono() [0x8310b02]
	/usr/local/bin/mono() [0x862a732]
	/usr/local/bin/mono() [0x8c46c6f]
	/usr/local/bin/mono() [0x8c46dbb]
	/usr/local/bin/mono() [0x8c46f72]
	/usr/local/bin/mono() [0x85b1e17]
	/usr/local/bin/mono() [0x85b245b]
	/usr/local/bin/mono() [0x85b26c1]
	/usr/local/bin/mono() [0x85d096b]
	/usr/local/bin/mono() [0x85d6cec]
	/usr/local/bin/mono() [0x81a14e0]
	/usr/local/bin/mono() [0x80c18bb]
	/usr/local/bin/mono() [0x80c2fb4]
	/usr/local/bin/mono() [0x80c3c9e]
	/usr/local/bin/mono() [0x8166089]
	[0xb76ed03e]

Debug info from gdb:

ptrace: Operation not permitted.
No threads.

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Revised BSD license

  Home   Conclusions   License   Play