コード例 #1
0
    // General parallel solution, using void Tasks with shared variable
    private static long countParallelN1(int range, int taskCount)
    {
        int         perTask = range / taskCount;
        LongCounter lc      = new LongCounter();

        Parallel.For(0, taskCount, t =>
                     { int from = perTask * t,
                       to = (t + 1 == taskCount) ? range : perTask * (t + 1);
                       for (int i = from; i < to; i++)
                       {
                           if (isPrime(i))
                           {
                               lc.increment();
                           }
                       }
                     });
        return(lc.get());
    }
コード例 #2
0
ファイル: TestCountPrimesTasks.cs プロジェクト: trahasch/SPPP
 // General parallel solution, using void Tasks with shared variable
 private static long countParallelN1(int range, int taskCount)
 {
     int perTask = range / taskCount;
     LongCounter lc = new LongCounter();
     Parallel.For(0, taskCount, t =>
       { int from = perTask * t,
     to = (t+1 == taskCount) ? range : perTask * (t+1);
     for (int i=from; i<to; i++)
       if (isPrime(i))
         lc.increment();
       });
     return lc.get();
 }