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(); }
public static int xFloorLog2(uint x) { x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); return(Bithacks.Ones(x) - 1); }
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); } }