Skip previously excluded by-divisor candidates

This commit is contained in:
Marek Lemańczyk committed 2025-09-29 14:46:37 +02:00
1 parent fc74f2b59b
commit 4d2c70da8b
1 file changed
+23
+23
View File
@@ -1,4 +1,5 @@
using System.Buffers; using System.Buffers;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -36,6 +37,7 @@ internal static class Program
private static UInt128 _divisor; private static UInt128 _divisor;
private static MersenneNumberDivisorGpuTester? _divisorTester; private static MersenneNumberDivisorGpuTester? _divisorTester;
private static IMersenneNumberDivisorByDivisorTester? _byDivisorTester; private static IMersenneNumberDivisorByDivisorTester? _byDivisorTester;
private static Dictionary<ulong, (bool DetailedCheck, bool PassedAllTests)>? _byDivisorPreviousResults;
private static ulong? _orderWarmupLimitOverride; private static ulong? _orderWarmupLimitOverride;
private static unsafe delegate*<ulong, ref ulong, ulong> _transformP; private static unsafe delegate*<ulong, ref ulong, ulong> _transformP;
private static long _state; private static long _state;
@@ -588,6 +590,9 @@ internal static class Program
} }
Dictionary<ulong, (bool DetailedCheck, bool PassedAllTests)>? previousResults = useByDivisor ? new Dictionary<ulong, (bool DetailedCheck, bool PassedAllTests)>() : null;
_byDivisorPreviousResults = previousResults;
if (File.Exists(ResultsFileName)) if (File.Exists(ResultsFileName))
{ {
Console.WriteLine("Processing previous results..."); Console.WriteLine("Processing previous results...");
@@ -597,6 +602,11 @@ internal static class Program
{ {
_primeCount++; _primeCount++;
} }
if (previousResults is not null)
{
previousResults[p] = (detailedCheck, passedAllTests);
}
}); });
} }
else else
@@ -772,6 +782,8 @@ internal static class Program
bool searched = false; bool searched = false;
bool detailed = false; bool detailed = false;
ulong allowedMax = 0UL; ulong allowedMax = 0UL;
Dictionary<ulong, (bool DetailedCheck, bool PassedAllTests)>? previousResults = _byDivisorPreviousResults;
int skippedByPreviousResults = 0;
_byDivisorPrecheckOnly = true; _byDivisorPrecheckOnly = true;
ulong startPrime = _byDivisorStartPrime; ulong startPrime = _byDivisorStartPrime;
@@ -784,6 +796,12 @@ internal static class Program
continue; continue;
} }
if (previousResults is not null && previousResults.TryGetValue(prime, out var previousResult) && !previousResult.PassedAllTests)
{
skippedByPreviousResults++;
continue;
}
if (!IsEvenPerfectCandidate(prime, divisorCyclesSearchLimit, out searched, out detailed)) if (!IsEvenPerfectCandidate(prime, divisorCyclesSearchLimit, out searched, out detailed))
{ {
PrintResult(prime, searched, detailed, false); PrintResult(prime, searched, detailed, false);
@@ -811,6 +829,11 @@ internal static class Program
_byDivisorPrecheckOnly = false; _byDivisorPrecheckOnly = false;
if (skippedByPreviousResults > 0)
{
Console.WriteLine($"Skipped {skippedByPreviousResults.ToString(CultureInfo.InvariantCulture)} primes excluded by previous results.");
}
if (states.Count == 0) if (states.Count == 0)
{ {
if (applyStartPrime) if (applyStartPrime)