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  1539   

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.10.1 (master/9fd3c7a Thu Sep 11 15:32:17 PDT 2014)
LLVM: yes(3.4svn-mono-mono/e656cac)
GC: sgen

 n-body C# Mono #7 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
   Optimized further with SIMD by Nigel Delaney
*/

using System;
using Mono.Simd;

class NBody
{
   public static void Main (String[] args)
   {
      int n = args.Length > 0 ? Int32.Parse (args [0]) : 10000;
      NBodySystem bodies = new NBodySystem ();
      Console.WriteLine ("{0:f9}", bodies.Energy ());
      bodies.Advance (0.01, n);
      Console.WriteLine ("{0:f9}", bodies.Energy ());
   }
}

class Body
{
   public Vector2d xy, z_, vxvy, vzv_, mass;
}

struct Pair
{
   public Body bi, bj;
}

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

   const double Pi = 3.141592653589793;
   const double Solarmass = 4 * Pi * Pi;
   const double DaysPeryear = 365.24;

   public NBodySystem ()
   {
      bodies = new Body[] {
         new Body () { // Sun
            mass = new Vector2d (Solarmass, Solarmass)
         },
         new Body () { // Jupiter
            xy = new Vector2d (
               4.84143144246472090e+00,
               -1.16032004402742839e+00),
            z_ = new Vector2d (
               -1.03622044471123109e-01,
               0),
            vxvy = new Vector2d (
               1.66007664274403694e-03 * DaysPeryear,
               7.69901118419740425e-03 * DaysPeryear),
            vzv_ = new Vector2d (
               -6.90460016972063023e-05 * DaysPeryear,
               0),
            mass = new Vector2d (
               9.54791938424326609e-04 * Solarmass,
               9.54791938424326609e-04 * Solarmass)
         },
         new Body () { // Saturn
            xy = new Vector2d (
               8.34336671824457987e+00,
               4.12479856412430479e+00),
            z_ = new Vector2d (
               -4.03523417114321381e-01,
               0.0),
            vxvy = new Vector2d (
               -2.76742510726862411e-03 * DaysPeryear,
               4.99852801234917238e-03 * DaysPeryear),
            vzv_ = new Vector2d (
               2.30417297573763929e-05 * DaysPeryear,
               0.0),
            mass = new Vector2d (
               2.85885980666130812e-04 * Solarmass,
               2.85885980666130812e-04 * Solarmass)
         },
         new Body () { // Uranus
            xy = new Vector2d (
               1.28943695621391310e+01,
               -1.51111514016986312e+01),
            z_ = new Vector2d (
               -2.23307578892655734e-01,
               0.0),
            
            vxvy = new Vector2d (
               2.96460137564761618e-03 * DaysPeryear,
               2.37847173959480950e-03 * DaysPeryear),
            vzv_ = new Vector2d (
               -2.96589568540237556e-05 * DaysPeryear,
               0.0),
            mass = new Vector2d (
               4.36624404335156298e-05 * Solarmass,
               4.36624404335156298e-05 * Solarmass)
         },
         new Body () { // Neptune
            xy = new Vector2d (
               1.53796971148509165e+01,
               -2.59193146099879641e+01),
            z_ = new Vector2d (
               1.79258772950371181e-01,
               0.0),

            vxvy = new Vector2d (
               2.68067772490389322e-03 * DaysPeryear,
               1.62824170038242295e-03 * DaysPeryear),
            vzv_ = new Vector2d (
               -9.51592254519715870e-05 * DaysPeryear,
               0.0),
            mass = new Vector2d (
               5.15138902046611451e-05 * Solarmass,
               5.15138902046611451e-05 * Solarmass)
         },
      };

      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++] = new Pair () { bi = bodies [i], bj = bodies [j] };        

      Vector2d pxpy = new Vector2d ();
      Vector2d pzp_ = new Vector2d ();
      foreach (var b in bodies) {
         pxpy += b.vxvy * b.mass;
         pzp_ += b.vzv_ * b.mass;
      }
      var sol = bodies [0];
      var solarMassPacked = new Vector2d (Solarmass, Solarmass);
      sol.vxvy = Vector2d.MinusOne * pxpy / solarMassPacked;
      sol.vzv_ = Vector2d.MinusOne * pzp_ / solarMassPacked;
   }

   public void Advance (double dt, int n)
   {
      var dtp = new Vector2d (dt, dt);
      for (int i = 0; i < n; i++) {      
         foreach (var p in pairs) {
            Body bi = p.bi, bj = p.bj;
            //get differences
            var dxdy = bi.xy - bj.xy; 
            var dzd_ = bi.z_ - bj.z_;
            //square the differences
            var d2xy = dxdy * dxdy;
            var d2z = dzd_ * dzd_;
            //get x^2+y^2+z^2 in both elements of the packed double
            //Note assumes second element of dz is zero
            var d2 = d2xy.HorizontalAdd (d2xy) + d2z.HorizontalAdd (d2z);
            var mag = dtp / (d2 * d2.Sqrt ());
            var bjmassTimesMag = bj.mass * mag;
            bi.vxvy -= dxdy * bjmassTimesMag;
            bi.vzv_ -= dzd_ * bjmassTimesMag; 
            var bimassTimesMag = bi.mass * mag;
            bj.vxvy += dxdy * bimassTimesMag;
            bj.vzv_ += dzd_ * bimassTimesMag;
         }
         foreach (var b in bodies) {
            b.xy += dtp * b.vxvy;
            b.z_ += dtp * b.vzv_;
         }
      }
   }

   public double Energy ()
   {
      double e = 0.0;
      for (int i = 0; i < bodies.Length; i++) {
         var bi = bodies [i];
         e += 0.5 * bi.mass.X * (bi.vxvy.X * bi.vxvy.X + bi.vxvy.Y * bi.vxvy.Y + bi.vzv_.X * bi.vzv_.X);
         for (int j = i + 1; j < bodies.Length; j++) {
            var bj = bodies [j];
            double dx = bi.xy.X - bj.xy.X, dy = bi.xy.Y - bj.xy.Y, dz = bi.z_.X - bj.z_.X;

            e -= (bi.mass * bj.mass).X / Math.Sqrt (dx * dx + dy * dy + dz * dz);
         }
      }
      return e;
   }
}

 make, command-line, and program output logs

Fri, 12 Sep 2014 13:42:50 GMT

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

COMMAND LINE:
/usr/local/bin/mono --llvm --gc=sgen nbody.csharp-7.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() [0x816577a]
	[0xb76e640c]
	[0xb76e6424]
	/lib/i386-linux-gnu/libc.so.6(gsignal+0x47) [0xb73ad577]
	/lib/i386-linux-gnu/libc.so.6(abort+0x143) [0xb73b09a3]
	/lib/i386-linux-gnu/libc.so.6(+0x276c7) [0xb73a66c7]
	/lib/i386-linux-gnu/libc.so.6(+0x27777) [0xb73a6777]
	/usr/local/bin/mono() [0x85b263f]
	/usr/local/bin/mono() [0x830987a]
	/usr/local/bin/mono() [0x830aaab]
	/usr/local/bin/mono() [0x830c112]
	/usr/local/bin/mono() [0x8625862]
	/usr/local/bin/mono() [0x8c41d9f]
	/usr/local/bin/mono() [0x8c41eeb]
	/usr/local/bin/mono() [0x8c420a2]
	/usr/local/bin/mono() [0x85ad427]
	/usr/local/bin/mono() [0x85ada6b]
	/usr/local/bin/mono() [0x85adcd1]
	/usr/local/bin/mono() [0x85cbf7b]
	/usr/local/bin/mono() [0x85d1e1c]
	/usr/local/bin/mono() [0x81a1d28]
	/usr/local/bin/mono() [0x80c134b]
	/usr/local/bin/mono() [0x80c27d4]
	/usr/local/bin/mono() [0x80c333e]
	/usr/local/bin/mono() [0x8166859]
	[0xb716c088]
	[0x952062c]

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