Exemplo n.º 1
0
 public void BenchSetup()
 {
     bodyPtr    = (Body *)Marshal.AllocHGlobal(Marshal.SizeOf <Body>() * 6);
     rsPtr      = (RS *)Marshal.AllocHGlobal(3 * 1024 * sizeof(double));
     nBodyPP    = Marshal.AllocHGlobal(Marshal.SizeOf <BodyVector>() * 12);
     nBodyPtr   = (BodyVector *)((ulong)nBodyPP - ((ulong)nBodyPP + 16) % 16);
     rPtr       = (R *)Marshal.AllocHGlobal(Marshal.SizeOf <R>() * 1024);
     magPtr     = (double *)Marshal.AllocHGlobal(sizeof(double) * 1024);
     bodySystem = new NBodySystem(bodyPtr);
     NBodySystem.Initialize(nBodyPtr);
 }
Exemplo n.º 2
0
    public static void AdvanceStaticIntr1(double dt, R *rPtr, double *magPtr, ref NBodySystem bodySystem, int count = 50000000)
    {
        Body *    items = bodySystem.bodies;
        const int N     = (BodyCount - 1) * BodyCount / 2;
        R *       r     = rPtr;
        double *  mag   = magPtr;

        {
            int      k     = 0;
            ref Body iBody = ref items[0];
            for (int j = 1; j < 5; ++j, ++k)
            {
                ref Body jBody = ref items[j];
                ref R    rf    = ref r[k];
        public unsafe void AdvanceByOne()
        {
            double *bvPtr = stackalloc double[sizeof(BodyVector) / sizeof(double)];

            NBodySystem.Initialize((BodyVector *)bvPtr);

            Body *      bodies     = stackalloc Body[5];
            NBodySystem bodySystem = new NBodySystem(bodies);

            // Other data structures
            RS *    rsaPtr  = stackalloc RS[1];
            R *     rPtr    = stackalloc R[1024];
            double *magPtr  = stackalloc double[1024];
            double *mag2Ptr = stackalloc double[1024];

            NBodySystem.AdvanceStaticIntrSoa(0.01, rsaPtr, magPtr);
            var result = NBodySystem.DumpBodyVector(5);

            NBodySystem.AdvanceStaticIntr2(0.01, rPtr, mag2Ptr, ref bodySystem);
            var expected = NBodySystem.DumpBodies(bodies, 5);

            Assert.Equal(expected, result);
        }
Exemplo n.º 4
0
        public sealed override unsafe void UnsafeReadReturn(ref NetCore.PkgReader pkg, void *arg)
        {
            R *pArg = (R *)arg;

            OnReadReturn(ref pkg, ref *pArg);
        }
Exemplo n.º 5
0
        GetRowsAndColumns
        (
            ICollection <IVertex> oVerticesToLayOut,
            LayoutContext oLayoutContext,
            out Int32 iRows,
            out Int32 iColumns
        )
        {
            Debug.Assert(oVerticesToLayOut != null);
            Debug.Assert(oLayoutContext != null);
            AssertValid();

        #if false
            Some definitions:

            W = rectangle width

                H = rectangle height

                    A = rectangle aspect ratio = W / H

                                                 V = number of vertices in graph

                                                     R = number of grid rows

                                                         C = number of grid columns


                                                             First simulataneous equation, allowing R and C to be fractional for
now:

            R * C = V


                    Second simulataneous equation:

                    C / R = A


                            Combining these equations yields:

                            1 / 2
                            C = (V * A)
        #endif

            Int32 V = oVerticesToLayOut.Count;

            // Compute the aspect ratio.

            RectangleF oRectangleF = oLayoutContext.GraphRectangle;
            Debug.Assert(oRectangleF.Height != 0);
            Double A = oRectangleF.Width / oRectangleF.Height;

            Double C = Math.Sqrt(V * A);
            Debug.Assert(A != 0);
            Double R = C / A;

            // Try the floor/ceiling combinations.

            // C floor, R floor

            iColumns = (Int32)Math.Floor(C);
            iRows    = (Int32)Math.Floor(R);

            if (RowsAndColumnsAreSufficient(iRows, iColumns, V))
            {
                return;
            }

            // C floor, R ceiling

            iRows++;

            if (RowsAndColumnsAreSufficient(iRows, iColumns, V))
            {
                return;
            }

            // C ceiling, R floor

            iColumns = (Int32)Math.Ceiling(C);
            iRows    = (Int32)Math.Floor(R);

            if (RowsAndColumnsAreSufficient(iRows, iColumns, V))
            {
                return;
            }

            // C ceiling, R ceiling

            iRows++;

            Debug.Assert(RowsAndColumnsAreSufficient(iRows, iColumns, V));
        }