Merge pull request #185 from mlemanczyk/codex/replace-trypopulatesmallprimefactorscpu-with-gpu
Use GPU helper for partial factor small primes
This commit is contained in:
1 file changed
+29
-3
@@ -729,14 +729,40 @@ internal static partial class PrimeOrderCalculator
|
||||
// We don't need to worry about leftovers, because we always use indexes within the calculated counts
|
||||
// primeSlots.Clear();
|
||||
// exponentSlots.Clear();
|
||||
if (!TryPopulateSmallPrimeFactorsCpu(value, limit, primeSlots, exponentSlots, out factorCount, out remaining))
|
||||
|
||||
counts = ThreadStaticPools.RentUlongIntDictionary(Math.Max(FactorSlotCount, 8));
|
||||
counts.Clear();
|
||||
|
||||
bool gpuPopulated = TryPopulateSmallPrimeFactorsGpu(value, limit, counts, out remaining);
|
||||
if (!gpuPopulated)
|
||||
{
|
||||
useDictionary = true;
|
||||
counts = ThreadStaticPools.RentUlongIntDictionary(Math.Max(factorCount, 8));
|
||||
counts.Clear();
|
||||
remaining = PopulateSmallPrimeFactorsCpu(value, limit, counts);
|
||||
}
|
||||
|
||||
int dictionaryCount = counts.Count;
|
||||
if (dictionaryCount <= FactorSlotCount)
|
||||
{
|
||||
int copyIndex = 0;
|
||||
foreach (KeyValuePair<ulong, int> entry in counts)
|
||||
{
|
||||
primeSlots[copyIndex] = entry.Key;
|
||||
exponentSlots[copyIndex] = entry.Value;
|
||||
copyIndex++;
|
||||
}
|
||||
|
||||
factorCount = copyIndex;
|
||||
ThreadStaticPools.ReturnUlongIntDictionary(counts);
|
||||
counts = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
useDictionary = true;
|
||||
factorCount = dictionaryCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (remaining > 1UL)
|
||||
{
|
||||
pending.Add(remaining);
|
||||
|
||||
Reference in new issue
Block a user