PrimeOrderCalculator.PartialFactorCpu simplified to work only with spans and throw exception if the number of factors is exceeded. PrimeOrderMode removed in favor of bool flag.
This commit is contained in:
1 parent
72890bf343
commit
7a242b3bfa
15 files changed
+337
-302
No files matched your search
@@ -4,39 +4,33 @@ namespace PerfectNumbers.Core;
|
||||
|
||||
internal static partial class PrimeOrderCalculator
|
||||
{
|
||||
internal enum PrimeOrderMode
|
||||
internal readonly struct PrimeOrderCalculatorConfig(uint smallFactorLimit, int pollardRhoMilliseconds, int maxPowChecks, bool strictMode)
|
||||
{
|
||||
Heuristic,
|
||||
Strict,
|
||||
}
|
||||
private static PrimeOrderCalculatorConfig _heuristicDefault = CreateHeuristicDefault(UnboundedTaskScheduler.ConfiguredThreadCount);
|
||||
|
||||
internal readonly struct PrimeOrderSearchConfig(uint smallFactorLimit, int pollardRhoMilliseconds, int maxPowChecks, PrimeOrderMode mode)
|
||||
{
|
||||
private static PrimeOrderSearchConfig _heuristicDefault = CreateHeuristicDefault(UnboundedTaskScheduler.ConfiguredThreadCount);
|
||||
|
||||
public static PrimeOrderSearchConfig HeuristicDefault
|
||||
public static PrimeOrderCalculatorConfig HeuristicDefault
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _heuristicDefault;
|
||||
}
|
||||
|
||||
public static readonly PrimeOrderSearchConfig StrictDefault = new(smallFactorLimit: 1_000_000, pollardRhoMilliseconds: 0, maxPowChecks: 0, PrimeOrderMode.Strict);
|
||||
public static readonly PrimeOrderCalculatorConfig StrictDefault = new(smallFactorLimit: 1_000_000, pollardRhoMilliseconds: 0, maxPowChecks: 0, true);
|
||||
|
||||
public static void ConfigureHeuristicDefault(int threadCount)
|
||||
{
|
||||
_heuristicDefault = CreateHeuristicDefault(threadCount);
|
||||
}
|
||||
|
||||
public static PrimeOrderSearchConfig CreateHeuristicDefault(int threadCount)
|
||||
public static PrimeOrderCalculatorConfig CreateHeuristicDefault(int threadCount)
|
||||
{
|
||||
int normalizedThreadCount = threadCount < 1 ? 1 : threadCount;
|
||||
return new(smallFactorLimit: 100_000, pollardRhoMilliseconds: normalizedThreadCount * 24, maxPowChecks: 24, PrimeOrderMode.Heuristic);
|
||||
return new(smallFactorLimit: 100_000, pollardRhoMilliseconds: normalizedThreadCount * 24, maxPowChecks: 24, false);
|
||||
}
|
||||
|
||||
public readonly uint SmallFactorLimit = smallFactorLimit;
|
||||
public readonly int PollardRhoMilliseconds = pollardRhoMilliseconds;
|
||||
public readonly int MaxPowChecks = maxPowChecks;
|
||||
public readonly PrimeOrderMode Mode = mode;
|
||||
public readonly bool StrictMode = strictMode;
|
||||
}
|
||||
|
||||
// TODO: Remove branching on the CPU / GPU paths
|
||||
|
||||
Reference in new issue
Block a user