Exemple #1
0
 protected override void ItemAction(int j)
 {
     if (Magma.IsPrime(j))
     {
         _c++;
     }
 }
Exemple #2
0
 protected override void ItemAction(int item)
 {
     if (Magma.IsPrime(item))
     {
         _primes.Add(item);
     }
 }
Exemple #3
0
        protected override void OnTorture()
        {
            while (!_abortSignal.IsCancellationRequested)
            {
                var count    = 0;
                var part     = Partitioner.Create(array);
                var syncRoot = new object();

                void TestIfPrime(int j)
                {
                    if (Magma.IsPrime(j))
                    {
                        lock (syncRoot) count++;
                    }
                }

                try
                {
                    Parallel.ForEach(part, new ParallelOptions
                    {
                        MaxDegreeOfParallelism = Environment.ProcessorCount,
                        CancellationToken      = _abortSignal.Token
                    }, TestIfPrime);
                }
                catch { }
            }
        }
Exemple #4
0
 protected override void ItemAction(int item)
 {
     if (Magma.IsPrime(item))
     {
         lock (_syncLock) _c++;
     }
 }
Exemple #5
0
 protected override void Benchmark(int[] array, Stopwatch t, ref int count)
 {
     t.Start();
     foreach (var j in array)
     {
         if (Magma.IsPrime(j))
         {
             count++;
         }
     }
     t.Stop();
 }
        public override void Run(int[] array)
        {
            var c = 0;

            foreach (var j in array)
            {
                if (Magma.IsPrime(j))
                {
                    c++;
                }
            }
            Count = c;
        }
Exemple #7
0
 protected override void Benchmark(int[] array, Stopwatch t, ref int count)
 {
     t.Start();
     count = array.Select(p => Magma.IsPrime(p)).Count(p => p);
     t.Stop();
 }