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  1485   

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.8.1 (master/0322d96 Wed Aug 13 11:49:57 PDT 2014)
LLVM: yes(3.4svn-mono-mono/e656cac)
GC: sgen

 n-body C# Mono #5 program source code

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

   contributed by Robert F. Tobler
   use of Mono.Simd by Markus Uhr
*/

using System;
using Mono.Simd;

using Pair = System.Tuple<Body,Body>;

class Body
{
   public Vector2d xy;
   public Vector2d z0;
   public Vector2d vxvy;
   public Vector2d vz00;
   public Vector2d mass;
}

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

   private const double pi = 3.141592653589793;
   private const double sm = 4.0*pi*pi; // solar mass
   private const double dpy = 365.24;   // days per year

   private Vector2d v2sm = new Vector2d(sm, sm);
   private Vector2d v2dpy = new Vector2d(dpy, dpy);

   public NBodySystem() {
      bodies = new Body[] {
         // Sun
         new Body() {
            mass = new Vector2d(sm, sm),
         },
         // Jupiter
         new Body() {
            xy = new Vector2d( 4.84143144246472090e+00, -1.16032004402742839e+00),
            z0 = new Vector2d(-1.03622044471123109e-01,  0.00000000000000000e+00),
            vxvy = new Vector2d( 1.66007664274403694e-03, 7.69901118419740425e-03)*v2dpy,
            vz00 = new Vector2d(-6.90460016972063023e-05, 0.00000000000000000e+00)*v2dpy,
            mass = new Vector2d( 9.54791938424326609e-04, 9.54791938424326609e-04)*v2sm
         },
         // Saturn
         new Body() {
            xy = new Vector2d( 8.34336671824457987e+00,  4.12479856412430479e+00),
            z0 = new Vector2d(-4.03523417114321381e-01,  0.00000000000000000e+00),
            vxvy = new Vector2d(-2.76742510726862411e-03, 4.99852801234917238e-03)*v2dpy,
            vz00 = new Vector2d( 2.30417297573763929e-05, 0.00000000000000000e+00)*v2dpy,
            mass = new Vector2d( 2.85885980666130812e-04, 2.85885980666130812e-04)*v2sm
         },
         // Uranus
         new Body() {
            xy = new Vector2d( 1.28943695621391310e+01, -1.51111514016986312e+01),
            z0 = new Vector2d(-2.23307578892655734e-01,  0.00000000000000000e+00),
            vxvy = new Vector2d( 2.96460137564761618e-03, 2.37847173959480950e-03)*v2dpy,
            vz00 = new Vector2d(-2.96589568540237556e-05, 0.00000000000000000e+00)*v2dpy,
            mass = new Vector2d( 4.36624404335156298e-05, 4.36624404335156298e-05)*v2sm
         },
         // Neptune
         new Body() {
            xy = new Vector2d( 1.53796971148509165e+01, -2.59193146099879641e+01),
            z0 = new Vector2d( 1.79258772950371181e-01,  0.00000000000000000e+00),
            vxvy = new Vector2d( 2.68067772490389322e-03, 1.62824170038242295e-03)*v2dpy,
            vz00 = new Vector2d(-9.51592254519715870e-05, 0.00000000000000000e+00)*v2dpy,
            mass = new Vector2d( 5.15138902046611451e-05, 5.15138902046611451e-05)*v2sm
         },
      };
      
      pairs = new Pair[bodies.Length*(bodies.Length-1)/2];      
      int pi = 0;
      for (int i = 0; i < bodies.Length-1; i++)
         for (int j = i+1; j < bodies.Length; j++)
            pairs[pi++] = Tuple.Create(bodies[i], bodies[j]);      

      Vector2d pxpy = Vector2d.Zero;
      Vector2d pz00 = Vector2d.Zero;
      foreach (var b in bodies) {
         pxpy -= b.vxvy*b.mass;
         pz00 -= b.vz00*b.mass;
      }
      var sol = bodies[0];
      sol.vxvy = pxpy/v2sm;
      sol.vz00 = pz00/v2sm;
   }

   public void Advance(double dt)
   {
      var dtdt = new Vector2d(dt, dt);
      int npairs = pairs.Length;
      for (int i=0; i<npairs; i++)
      {
         var p = pairs[i];
         var bi = p.Item1;
         var bj = p.Item2;
         var dxdy = bi.xy - bj.xy;
         var dz00 = bi.z0 - bj.z0;
         var tmp = VectorOperations.HorizontalAdd(dxdy*dxdy, dz00*dz00);
         var d2 = VectorOperations.HorizontalAdd(tmp, tmp);
         var mag = dtdt/(d2*VectorOperations.Sqrt(d2));
         bi.vxvy -= dxdy*bj.mass*mag; bj.vxvy += dxdy*bi.mass*mag;
         bi.vz00 -= dz00*bj.mass*mag; bj.vz00 += dz00*bi.mass*mag;
      }
      int nbodies = bodies.Length;
      for (int i=0; i<nbodies; i++)
      {
         var b = bodies[i];
         b.xy += dtdt*b.vxvy;
         b.z0 += dtdt*b.vz00;
      }
   }

   public double Energy()
   {
      var e = 0.0;
      for (int i = 0; i < bodies.Length; i++)
      {
         var bi = bodies[i];
         var tmp = VectorOperations.HorizontalAdd(bi.vxvy*bi.vxvy, bi.vz00*bi.vz00);
         e += 0.5*bi.mass.X*(tmp.X + tmp.Y);
         for (int j = i+1; j < bodies.Length; j++)
         {
            var bj = bodies[j];
            var dxdy = bi.xy - bj.xy;
            var dz00 = bi.z0 - bj.z0;
            var tm2 = VectorOperations.HorizontalAdd(dxdy*dxdy, dz00*dz00);
            e -= (bi.mass.X*bj.mass.X)/Math.Sqrt(tm2.X + tm2.Y);
         }
      }
      return e;
   }
}

class NBody
{
   public static void Main(String[] args)
   {
      int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000;

      NBodySystem bodies = new NBodySystem();
      // initial energy
      Console.WriteLine("{0:f9}", bodies.Energy());

      for (int i=0; i<n; i++)
         bodies.Advance(0.01);
      // final energy
      Console.WriteLine("{0:f9}", bodies.Energy());
   }
}

 make, command-line, and program output logs

Thu, 14 Aug 2014 13:50:24 GMT

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

COMMAND LINE:
/usr/local/bin/mono --llvm --gc=sgen nbody.csharp-5.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.Main (string[]) <0x0003a>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	/usr/local/bin/mono() [0x816507a]
	[0xb776940c]
	[0xb7769424]
	/lib/i386-linux-gnu/libc.so.6(gsignal+0x47) [0xb7430937]
	/lib/i386-linux-gnu/libc.so.6(abort+0x143) [0xb7433d63]
	/lib/i386-linux-gnu/libc.so.6(+0x27a87) [0xb7429a87]
	/lib/i386-linux-gnu/libc.so.6(+0x27b37) [0xb7429b37]
	/usr/local/bin/mono() [0x85b0b9f]
	/usr/local/bin/mono() [0x8307dda]
	/usr/local/bin/mono() [0x830900b]
	/usr/local/bin/mono() [0x830a672]
	/usr/local/bin/mono() [0x8623dc2]
	/usr/local/bin/mono() [0x8c402ff]
	/usr/local/bin/mono() [0x8c4044b]
	/usr/local/bin/mono() [0x8c40602]
	/usr/local/bin/mono() [0x85ab987]
	/usr/local/bin/mono() [0x85abfcb]
	/usr/local/bin/mono() [0x85ac231]
	/usr/local/bin/mono() [0x85ca4db]
	/usr/local/bin/mono() [0x85d037c]
	/usr/local/bin/mono() [0x81a1568]
	/usr/local/bin/mono() [0x80c1cfb]
	/usr/local/bin/mono() [0x80c3184]
	/usr/local/bin/mono() [0x80c3cee]
	/usr/local/bin/mono() [0x8166119]
	[0xb7754088]
	[0x9bde49c]

Debug info from gdb:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
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