예제 #1
0
        public static void Parallel(int[] e)
        {
            Campy.Parallel.Sticky(e);
            int N     = e.Length;
            int log2n = Bithacks.FloorLog2(N);

            for (int level = 1; level <= log2n; level++)
            {
                int step = Bithacks.Power2(level);
                Campy.Parallel.For(N / step, idx =>
                {
                    var i = step * (idx + 1) - 1;
                    e[i]  = e[i - step / 2] + e[i];
                });
            }
            Campy.Sequential.For(1, idx => { e[N - 1] = 0; });
            for (int level = log2n; level > 0; level--)
            {
                int step = Bithacks.Power2(level);
                Campy.Parallel.For(N / step, idx =>
                {
                    var i           = step * (idx + 1) - 1;
                    var l           = e[i - step / 2];
                    var r           = e[i];
                    e[i]            = r + l;
                    e[i - step / 2] = r;
                });
            }
            Campy.Parallel.Sync();
        }
예제 #2
0
        public static int CeilingLog2(int v)
        {
            int r = Bithacks.FloorLog2(v);

            if (r < 0)
            {
                return(r);
            }
            if (v != (uint)Bithacks.Power2((uint)r))
            {
                return(r + 1);
            }
            else
            {
                return(r);
            }
        }