EvenPerfectBitScanner fully migrated to MersenneDivisorCycles. Tiny optimization.
This commit is contained in:
1 parent
74837a407e
commit
b53d00a8cc
2 files changed
+29
-17
No files matched your search
@@ -179,18 +179,15 @@ internal static class CandidatesCalculator
|
|||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
internal static ulong AdvancePrime(ulong value, ref ulong remainder, ref bool limitReached)
|
internal static ulong AdvancePrime(ulong value, ref ulong remainder, ref bool limitReached) => _transformMode switch
|
||||||
{
|
{
|
||||||
return _transformMode switch
|
PrimeTransformMode.Bit => CandidateBitTransform.Transform(value, ref remainder, ref limitReached),
|
||||||
{
|
PrimeTransformMode.Add => CandidateAddTransform.Transform(value, ref remainder, ref limitReached),
|
||||||
PrimeTransformMode.Bit => CandidateBitTransform.Transform(value, ref remainder, ref limitReached),
|
_ => CandidateAddPrimesTransform.Transform(value, ref remainder, ref limitReached),
|
||||||
PrimeTransformMode.Add => CandidateAddTransform.Transform(value, ref remainder, ref limitReached),
|
};
|
||||||
_ => CandidateAddPrimesTransform.Transform(value, ref remainder, ref limitReached),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static int ReserveBlock(ulong[] buffer, int blockSize, ref bool limitReached)
|
internal static int ReserveBlock(ulong[] buffer, int blockSize, ref bool limitReached)
|
||||||
{
|
{
|
||||||
Span<ulong> bufferSpan = new(buffer);
|
Span<ulong> bufferSpan = new(buffer);
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ internal static class Program
|
|||||||
Directory.CreateDirectory(PerfectNumberConstants.ByDivisorStateDirectory);
|
Directory.CreateDirectory(PerfectNumberConstants.ByDivisorStateDirectory);
|
||||||
|
|
||||||
|
|
||||||
MersenneDivisorCycles mersenneDivisorCycles = new();
|
|
||||||
if (!File.Exists(cyclesPath) || continueCyclesGeneration)
|
if (!File.Exists(cyclesPath) || continueCyclesGeneration)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Generating divisor cycles '{cyclesPath}' for all p <= {PerfectNumberConstants.MaxQForDivisorCycles}...");
|
Console.WriteLine($"Generating divisor cycles '{cyclesPath}' for all p <= {PerfectNumberConstants.MaxQForDivisorCycles}...");
|
||||||
@@ -147,7 +146,9 @@ internal static class Program
|
|||||||
if (continueCyclesGeneration && File.Exists(cyclesPath))
|
if (continueCyclesGeneration && File.Exists(cyclesPath))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Finding last divisor position...");
|
Console.WriteLine("Finding last divisor position...");
|
||||||
(nextPosition, completeCount) = MersenneDivisorCycles.FindLast(cyclesPath);
|
(nextPosition, completeCount) = useGpuCycles
|
||||||
|
? MersenneDivisorCyclesGpu.FindLast(cyclesPath)
|
||||||
|
: MersenneDivisorCyclesCpu.FindLast(cyclesPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useGpuCycles)
|
if (useGpuCycles)
|
||||||
@@ -162,22 +163,36 @@ internal static class Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Wire GenerateGpu to the unrolled-hex kernel that led the MersenneDivisorCycleLengthGpuBenchmarks once it lands.
|
// TODO: Wire GenerateGpu to the unrolled-hex kernel that led the MersenneDivisorCycleLengthGpuBenchmarks once it lands.
|
||||||
MersenneDivisorCycles.GenerateGpu(cyclesPath, PerfectNumberConstants.MaxQForDivisorCycles, cyclesBatchSize, skipCount: completeCount, nextPosition: nextPosition);
|
MersenneDivisorCyclesGpu.GenerateGpu(cyclesPath, PerfectNumberConstants.MaxQForDivisorCycles, cyclesBatchSize, skipCount: completeCount, nextPosition: nextPosition);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MersenneDivisorCycles.Generate(cyclesPath, PerfectNumberConstants.MaxQForDivisorCycles);
|
MersenneDivisorCyclesCpu.Generate(cyclesPath, PerfectNumberConstants.MaxQForDivisorCycles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Loading divisor cycles into memory...");
|
Console.WriteLine($"Loading divisor cycles into memory...");
|
||||||
if (string.Equals(Path.GetExtension(cyclesPath), ".csv", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(Path.GetExtension(cyclesPath), ".csv", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
MersenneDivisorCycles.Shared.LoadFrom(cyclesPath);
|
if (useGpuCycles)
|
||||||
|
{
|
||||||
|
MersenneDivisorCyclesGpu.Shared.LoadFrom(cyclesPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MersenneDivisorCyclesCpu.Shared.LoadFrom(cyclesPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MersenneDivisorCycles.Shared.LoadFrom(cyclesPath);
|
if (useGpuCycles)
|
||||||
|
{
|
||||||
|
MersenneDivisorCyclesGpu.Shared.LoadFrom(cyclesPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MersenneDivisorCyclesCpu.Shared.LoadFrom(cyclesPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DivisorCycleCache.SetDivisorCyclesBatchSize(cyclesBatchSize);
|
DivisorCycleCache.SetDivisorCyclesBatchSize(cyclesBatchSize);
|
||||||
|
|||||||
Reference in new issue
Block a user