Assign contiguous by-divisor ranges per worker
This commit is contained in:
1 parent
bcf50cf763
commit
ebfdc7d8b8
1 file changed
+26
-1
@@ -290,7 +290,32 @@ public static class MersenneNumberDivisorByDivisorTester
|
||||
MaxDegreeOfParallelism = workerCount
|
||||
};
|
||||
|
||||
Parallel.ForEach(filteredPrimes, options, ProcessPrime);
|
||||
primeCount = filteredPrimes.Count; // Reusing primeCount to track the filtered count.
|
||||
int primesPerWorker = (primeCount + workerCount - 1) / workerCount;
|
||||
|
||||
Parallel.For(
|
||||
0,
|
||||
workerCount,
|
||||
options,
|
||||
workerIndex =>
|
||||
{
|
||||
int start = workerIndex * primesPerWorker;
|
||||
if (start >= primeCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int end = start + primesPerWorker;
|
||||
if (end > primeCount)
|
||||
{
|
||||
end = primeCount;
|
||||
}
|
||||
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
ProcessPrime(filteredPrimes[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user