示例#1
0
    /// <summary>
    /// Run the test with a value type (DoubleStruct) and the MPI.NET "add" operation.
    /// </summary>
    private static void testValueType(int bufflen, int n, int nRepeat, ref double tlast)
    {
        DoubleStruct[] sendBuffer = new DoubleStruct[bufflen]; // Align the data?  Some day.  Maybe.
        DoubleStruct[] recvBuffer = new DoubleStruct[bufflen];

        bwstats[n].t = 1e99;
        double t1 = 0, t2 = 0;

        for (int i = 0; i < TRIALS; i++)
        {
            Communicator.world.Barrier();
            double t0 = when();
            for (int j = 0; j < nRepeat; j++)
            {
                comm.Allreduce(sendBuffer, Operation <DoubleStruct> .Add, ref recvBuffer);
            }
            double t = (when() - t0) / (2.0 * nRepeat);
            t2                 += t * t;
            t1                 += t;
            bwstats[n].t        = Math.Min(bwstats[n].t, t);
            bwstats[n].variance = t2 / TRIALS - t1 / TRIALS * t1 / TRIALS;
            tlast               = bwstats[n].t;
            bwstats[n].bits     = bufflen * sizeof(double) * 8;
            bwstats[n].bps      = bwstats[n].bits / (bwstats[n].t * 1024 * 1024);
            bwstats[n].repeat   = nRepeat;
        }
    }
        public static unsafe int SizeOf <T>() where T : struct
        {
            DoubleStruct <T> doubleStruct = DoubleStruct <T> .Value;

            TypedReference tRef0 = __makeref(doubleStruct.First);
            TypedReference tRef1 = __makeref(doubleStruct.Second);

            // NB: Mono doesn't like these... LOL
            //TypedReference* address0 = &tRef0;
            //TypedReference* address1 = &tRef1;

            bool use2nd = Environment.OSVersion.Platform > PlatformID.WinCE;

            IntPtr firstValueAddress0  = *(IntPtr *)&tRef0;
            IntPtr secondValueAddress0 = *((IntPtr *)&tRef0 + 1);
            IntPtr firstValueAddress1  = *(IntPtr *)&tRef1;
            IntPtr secondValueAddress1 = *((IntPtr *)&tRef1 + 1);

            int size = 0;

            if (use2nd /* firstValueAddress0 == firstValueAddress1 */)
            {
                size = (int)((byte *)secondValueAddress1 - (byte *)secondValueAddress0);
            }
            else
            {
                size = (int)((byte *)firstValueAddress1 - (byte *)firstValueAddress0);
            }

            return(size);
        }
示例#3
0
        public static string GetDoubleInBinary(this double num)
        {
            DoubleStruct  newDouble = new DoubleStruct(num);
            long          numInLong = newDouble.lng;
            StringBuilder bits      = new StringBuilder();
            char          sign      = '0';

            if (numInLong >> 63 == -1)
            {
                sign = '1';
            }
            long mask = 1L;

            for (int i = 0; i < 63; i++)
            {
                bits.Append((numInLong & mask) >> i).ToString();
                mask = mask << 1;
            }
            StringBuilder result = new StringBuilder();

            foreach (var item in bits.ToString().Reverse())
            {
                result.Append(item);
            }
            return(sign.ToString() + result.ToString());
        }
示例#4
0
    public void TestDoubleStructWithIn()
    {
        var a = new DoubleStruct(1);
        var b = new DoubleStruct(2);

        for (var i = 1000000000; i > 0; --i)
        {
            DoubleStruct.AddWithIn(a, b);
        }
    }
示例#5
0
            public static unsafe int SizeOf()
            {
                DoubleStruct doubleStruct = default(DoubleStruct);

                TypedReference tRef0 = __makeref(doubleStruct.value0);
                TypedReference tRef1 = __makeref(doubleStruct.value1);

                IntPtr ptrToT0 = *((IntPtr *)&tRef0);
                IntPtr ptrToT1 = *((IntPtr *)&tRef1);

                return((int)(((byte *)ptrToT1) - ((byte *)ptrToT0)));
            }
        public static int SizeOf <T>()
        {
            DoubleStruct <T> doubleStruct = DoubleStruct <T> .Value;
            TypedReference   tRef0 = __makeref(doubleStruct.First);
            TypedReference   tRef1 = __makeref(doubleStruct.Second);
            IntPtr           ptrToT0, ptrToT1;

            if (PlatformHelper.IsMonoRuntime)
            {
                ptrToT0 = *((IntPtr *)&tRef0 + 1);
                ptrToT1 = *((IntPtr *)&tRef1 + 1);
            }
            else
            {
                ptrToT0 = *(IntPtr *)&tRef0;
                ptrToT1 = *(IntPtr *)&tRef1;
            }

            return((int)((byte *)ptrToT1 - (byte *)ptrToT0));
        }
示例#7
0
        /// <summary>
        /// write a double struct
        /// </summary>
        /// <param name="data"></param>
        public void Write(ref double data)
        {
            if (Length + 8 > _Buffer.Length)
            {
                _capacity += 8;
                Resize();
            }
            var value = new DoubleStruct()
            {
                Value = data
            };

            _Buffer[Length]     = value.Byte0;
            _Buffer[Length + 1] = value.Byte1;
            _Buffer[Length + 2] = value.Byte2;
            _Buffer[Length + 3] = value.Byte3;
            _Buffer[Length + 4] = value.Byte4;
            _Buffer[Length + 5] = value.Byte5;
            _Buffer[Length + 6] = value.Byte6;
            _Buffer[Length + 7] = value.Byte7;
            Length += 8;
        }
示例#8
0
    /// <summary>
    /// Run the test with a value type (DoubleStruct) and the MPI.NET "add" operation.
    /// </summary>
    private static void testValueType(int bufflen, int n, int nRepeat, ref double tlast)
    {
        DoubleStruct[] sendBuffer = new DoubleStruct[bufflen]; // Align the data?  Some day.  Maybe.
        DoubleStruct[] recvBuffer = new DoubleStruct[bufflen];

        bwstats[n].t = 1e99;
        double t1 = 0, t2 = 0;

        for (int i = 0; i < TRIALS; i++)
        {
            Communicator.world.Barrier();
            double t0 = when();
            for (int j = 0; j < nRepeat; j++)
            {
                comm.Allreduce(sendBuffer, Operation<DoubleStruct>.Add, ref recvBuffer);
            }
            double t = (when() - t0) / (2.0 * nRepeat);
            t2 += t * t;
            t1 += t;
            bwstats[n].t = Math.Min(bwstats[n].t, t);
            bwstats[n].variance = t2 / TRIALS - t1 / TRIALS * t1 / TRIALS;
            tlast = bwstats[n].t;
            bwstats[n].bits = bufflen * sizeof(double) * 8;
            bwstats[n].bps = bwstats[n].bits / (bwstats[n].t * 1024 * 1024);
            bwstats[n].repeat = nRepeat;
        }
    }