Additional checks will be skipped in bydivisor mode to speed up calculations. Console output extended.

This commit is contained in:
Marek Lemańczyk committed 2025-09-21 14:23:56 +02:00
1 parent 562d2adc3e
commit d117921c3a
2 files changed
+11 -1

No files matched your search

+4 -1
View File
@@ -1440,7 +1440,7 @@ internal static class Program
} }
// Fast residue-based composite check for p using small primes // Fast residue-based composite check for p using small primes
if (!_useDivisor && IsCompositeByResidues(p)) if (!_useDivisor && !_useByDivisorMode && IsCompositeByResidues(p))
{ {
searchedMersenne = false; searchedMersenne = false;
detailedCheck = false; detailedCheck = false;
@@ -1450,6 +1450,8 @@ internal static class Program
// If primes-device=gpu, route p primality through GPU-assisted sieve (optional MR later) // If primes-device=gpu, route p primality through GPU-assisted sieve (optional MR later)
// TODO: Add deterministic Miller–Rabin rounds in GPU path for 64-bit range. // TODO: Add deterministic Miller–Rabin rounds in GPU path for 64-bit range.
if (!_useByDivisorMode)
{
bool isPrimeP = GpuContextPool.ForceCpu bool isPrimeP = GpuContextPool.ForceCpu
? PrimeTesters.Value!.IsPrime(p, CancellationToken.None) ? PrimeTesters.Value!.IsPrime(p, CancellationToken.None)
: PrimeTesters.Value!.IsPrimeGpu(p, CancellationToken.None); : PrimeTesters.Value!.IsPrimeGpu(p, CancellationToken.None);
@@ -1458,6 +1460,7 @@ internal static class Program
_lastCompositeP = true; _lastCompositeP = true;
return false; return false;
} }
}
searchedMersenne = true; searchedMersenne = true;
if (_useByDivisorMode) if (_useByDivisorMode)
@@ -274,12 +274,19 @@ public sealed class MersenneNumberDivisorByDivisorGpuTester
} }
int offset = 0; int offset = 0;
int consoleStatus = 0;
while (offset < primes.Length) while (offset < primes.Length)
{ {
int batchSize = Math.Min(_owner._gpuBatchSize, primes.Length - offset); int batchSize = Math.Min(_owner._gpuBatchSize, primes.Length - offset);
Span<ulong> primeSpan = _primesHost.AsSpan(0, batchSize); Span<ulong> primeSpan = _primesHost.AsSpan(0, batchSize);
primes.Slice(offset, batchSize).CopyTo(primeSpan); primes.Slice(offset, batchSize).CopyTo(primeSpan);
if (++consoleStatus == PerfectNumberConstants.ConsoleInterval)
{
Console.WriteLine($"...processed by-divisor candidate = {primes[0]}");
consoleStatus = 0;
}
var primesView = _primesBuffer.View.SubView(0, batchSize); var primesView = _primesBuffer.View.SubView(0, batchSize);
var hitsView = _hitsBuffer.View.SubView(0, batchSize); var hitsView = _hitsBuffer.View.SubView(0, batchSize);