Exemple #1
0
        public ScalarLinqRenderer(Action <int, int, int> dp, Func <bool> abortFunc)
            : base(dp, abortFunc)
        {
            Pair[] pairs = Enumerable.Range(0, 312).SelectMany(y => Enumerable.Range(0, 534).Select(x => new Pair {
                X = x, Y = y
            })).ToArray();
            int[] output = Enumerable.Range(0, pairs.Length).ToArray();
            this.context = new GpuContext();
            this._pairs  = context.CreateGpuArray(pairs);
            this._output = context.CreateGpuArray(output);

            parFunc = ParallelExtensions.Compile <float, float, float, int[]>(
                (_ymin, _xmin, _step) =>
                (from pair in pairs.AsParallelQueryExpr()
                 let _y = _ymin + _step * pair.Y
                          let _x = _xmin + _step * pair.X
                                   let c = new MyComplex(_x, _y)
                                           let iters = EnumerableEx.Generate(c, x => x.SquareLength < limit, x => x * x + c, x => x)
                                                       .Take(max_iters)
                                                       .Count()
                                                       select iters).ToArray()
                );

            seqFunc = Extensions.Compile <float, float, float, int[]>(
                (_ymin, _xmin, _step) =>
                (from pair in pairs.AsQueryExpr()
                 let _y = _ymin + _step * pair.Y
                          let _x = _xmin + _step * pair.X
                                   let c = new MyComplex(_x, _y)
                                           let iters = EnumerableEx.Generate(c, x => x.SquareLength < limit, x => x * x + c, x => x)
                                                       .Take(max_iters)
                                                       .Count()
                                                       select iters).ToArray()
                );
        }
        public static async Task <IEnumerable <TimeSpan> > LoadSeveralTimes(Uri uri, int times, CancellationToken token)
        {
            var tempQueue = new ConcurrentQueue <TimeSpan>();

            await ParallelExtensions.ForAsync(0, times, async i =>
            {
                tempQueue.Enqueue(await LoadTimeMeasuringAsync(uri).ConfigureAwait(false));
            }, token).ConfigureAwait(false);

            return(tempQueue);
        }
Exemple #3
0
        static void testParallelWhile()
        {
            //adds support for parallel while (missing in .NET)
            //WATCH OUT: there is a chance that the number of iterations are larger than it should be
            //that is because threads are invoked in parallel and (NUM_THREDS-1) threads are looking the old state of the provided condition

            const int           MAX_ITER = 1;
            ConcurrentBag <int> bag      = new ConcurrentBag <int>();

            ParallelExtensions.While(() => bag.Count < MAX_ITER, (loopState) =>
                                     //System.Threading.Tasks.Parallel.For(0, MAX_ITER, (_) =>
            {
                bag.Add(0);
                Console.WriteLine("Count: {0}", bag.Count);
            });

            Console.WriteLine("Final count: {0}", bag.Count);
        }
Exemple #4
0
        public void PreCompileFunc()
        {
            Prop.ForAll <int>(i =>
            {
                if (i < 1)
                {
                    return(true);
                }

                var t = ParallelExtensions.Compile <int, int>(m =>
                                                              Enumerable.Range(1, m).AsParallelQueryExpr().Sum());

                var x = t(i);

                var y = Enumerable.Range(1, i).AsParallel().Sum();

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }