diff --git a/PerfectNumbers.Core/Gpu/GpuKernelLease.cs b/PerfectNumbers.Core/Gpu/GpuKernelLease.cs index 4d4f6ee..914f026 100644 --- a/PerfectNumbers.Core/Gpu/GpuKernelLease.cs +++ b/PerfectNumbers.Core/Gpu/GpuKernelLease.cs @@ -6,7 +6,7 @@ using static PerfectNumbers.Core.Gpu.GpuContextPool; namespace PerfectNumbers.Core.Gpu; -public sealed class GpuKernelLease : IDisposable +public sealed class GpuKernelLease { private static readonly ConcurrentQueue Pool = new(); @@ -702,8 +702,7 @@ public sealed class GpuKernelLease : IDisposable public void Dispose() { - Dispose(disposing: true); - System.GC.SuppressFinalize(this); + Dispose(disposing: false); } public readonly struct ExecutionScope @@ -715,7 +714,7 @@ public sealed class GpuKernelLease : IDisposable _lock = sync; if (_lock is not null) { - // Monitor.Enter(_lock); + Monitor.Enter(_lock); } } @@ -723,7 +722,7 @@ public sealed class GpuKernelLease : IDisposable { if (_lock is not null) { - // Monitor.Exit(_lock); + Monitor.Exit(_lock); } } } diff --git a/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs b/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs index ec06822..b120919 100644 --- a/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs +++ b/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs @@ -82,10 +82,6 @@ internal static partial class PrimeOrderCalculator for (int i = 0; i < length; i++) { ulong factor = factorSpan[i].Value; - if (factor == 0UL) - { - continue; - } ulong reduced = phi / factor; if (Pow2EqualsOneCpu(reduced, prime, divisorData)) { @@ -643,16 +639,16 @@ internal static partial class PrimeOrderCalculator private static bool Pow2EqualsOneCpu(ulong exponent, ulong prime, in MontgomeryDivisorData divisorData) { // if (IsGpuPow2Allowed) - // { + { ulong remainder = exponent.Pow2MontgomeryModWindowedGpu(divisorData, false); // GpuPow2ModStatus status = PrimeOrderGpuHeuristics.TryPow2Mod(exponent, prime, out ulong remainder, divisorData); // if (status == GpuPow2ModStatus.Success) // { return remainder == 1UL; // } - // } + } - // return exponent.Pow2MontgomeryModWindowedCpu(divisorData, keepMontgomery: false) == 1UL; + return exponent.Pow2MontgomeryModWindowedCpu(divisorData, keepMontgomery: false) == 1UL; } // [ThreadStatic] @@ -748,21 +744,21 @@ internal static partial class PrimeOrderCalculator // int dictionaryCount = counts.Count; // if (dictionaryCount <= FactorSlotCount) // { - int copyIndex = 0; - foreach (KeyValuePair entry in counts) - { - primeSlots[copyIndex] = entry.Key; - exponentSlots[copyIndex] = entry.Value; - copyIndex++; - } + // int copyIndex = 0; + // foreach (KeyValuePair entry in counts) + // { + // primeSlots[copyIndex] = entry.Key; + // exponentSlots[copyIndex] = entry.Value; + // copyIndex++; + // } - factorCount = copyIndex; - ThreadStaticPools.ReturnUlongIntDictionary(counts); - counts = null; + // factorCount = copyIndex; + // ThreadStaticPools.ReturnUlongIntDictionary(counts); + // counts = null; // } // else // { - // useDictionary = true; + useDictionary = true; // factorCount = dictionaryCount; // } }