MethodImpl attributes added. Unnecessary try...finally blocks removed.
This commit is contained in:
1 parent
189013b849
commit
23748ad3d2
1 file changed
+100
-133
@@ -11,6 +11,7 @@ namespace PerfectNumbers.Core;
|
|||||||
|
|
||||||
public static class MersenneNumberDivisorByDivisorTester
|
public static class MersenneNumberDivisorByDivisorTester
|
||||||
{
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static void Run(
|
public static void Run(
|
||||||
List<ulong> candidates,
|
List<ulong> candidates,
|
||||||
ref MersenneNumberDivisorByDivisorCpuTesterWithCpuOrder tester,
|
ref MersenneNumberDivisorByDivisorCpuTesterWithCpuOrder tester,
|
||||||
@@ -41,6 +42,7 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
Action<ulong, bool, bool, bool, BigInteger> pr) =>
|
Action<ulong, bool, bool, bool, BigInteger> pr) =>
|
||||||
RunCpuOrderFiltered(filteredPrimes, prototype, workerCount, partitionSize, mc, cc, pr));
|
RunCpuOrderFiltered(filteredPrimes, prototype, workerCount, partitionSize, mc, cc, pr));
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static void Run(
|
public static void Run(
|
||||||
List<ulong> candidates,
|
List<ulong> candidates,
|
||||||
ref MersenneNumberDivisorByDivisorCpuTesterWithHybridOrder tester,
|
ref MersenneNumberDivisorByDivisorCpuTesterWithHybridOrder tester,
|
||||||
@@ -71,6 +73,7 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
Action<ulong, bool, bool, bool, BigInteger> pr) =>
|
Action<ulong, bool, bool, bool, BigInteger> pr) =>
|
||||||
RunHybridOrderFiltered(filteredPrimes, prototype, workerCount, partitionSize, mc, cc, pr));
|
RunHybridOrderFiltered(filteredPrimes, prototype, workerCount, partitionSize, mc, cc, pr));
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static void Run(
|
public static void Run(
|
||||||
List<ulong> candidates,
|
List<ulong> candidates,
|
||||||
ref MersenneNumberDivisorByDivisorCpuTesterWithGpuOrder tester,
|
ref MersenneNumberDivisorByDivisorCpuTesterWithGpuOrder tester,
|
||||||
@@ -200,7 +203,7 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static ulong GetAllowedDivisorLimitForSpan(BigInteger divisorLimit)
|
public static ulong GetAllowedDivisorLimitForSpan(BigInteger divisorLimit)
|
||||||
{
|
{
|
||||||
if (divisorLimit.IsZero)
|
if (divisorLimit.IsZero)
|
||||||
@@ -227,6 +230,7 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
return (BigInteger.One << (int)(maxPrime - 1UL)) - BigInteger.One;
|
return (BigInteger.One << (int)(maxPrime - 1UL)) - BigInteger.One;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static BigInteger ComputeAllowedMaxDivisorBig(ulong prime, BigInteger divisorLimit)
|
public static BigInteger ComputeAllowedMaxDivisorBig(ulong prime, BigInteger divisorLimit)
|
||||||
{
|
{
|
||||||
if (prime <= 1UL)
|
if (prime <= 1UL)
|
||||||
@@ -687,6 +691,7 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
Action<ulong, bool, bool, bool, BigInteger> printResult)
|
Action<ulong, bool, bool, bool, BigInteger> printResult)
|
||||||
where TTester : struct;
|
where TTester : struct;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
private static void RunStructTester<TTester>(
|
private static void RunStructTester<TTester>(
|
||||||
List<ulong> candidates,
|
List<ulong> candidates,
|
||||||
ref TTester tester,
|
ref TTester tester,
|
||||||
@@ -897,18 +902,12 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
{
|
{
|
||||||
DeterministicRandomCpu.Initialize();
|
DeterministicRandomCpu.Initialize();
|
||||||
var session = new MersenneNumberDivisorByDivisorPrimeScanSessionWithCpuOrder(prototypeCopy, markComposite, clearComposite, printResult);
|
var session = new MersenneNumberDivisorByDivisorPrimeScanSessionWithCpuOrder(prototypeCopy, markComposite, clearComposite, printResult);
|
||||||
try
|
foreach (ulong prime in filteredPrimes)
|
||||||
{
|
{
|
||||||
foreach (ulong prime in filteredPrimes)
|
session.ProcessPrime(prime);
|
||||||
{
|
|
||||||
session.ProcessPrime(prime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
session.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,33 +927,28 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
startGate.Wait();
|
startGate.Wait();
|
||||||
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
|
|
||||||
try
|
while (true)
|
||||||
{
|
{
|
||||||
while (true)
|
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
||||||
|
if (start >= totalCount)
|
||||||
{
|
{
|
||||||
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
break;
|
||||||
if (start >= totalCount)
|
}
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int end = start + partitionSize;
|
int end = start + partitionSize;
|
||||||
if (end > totalCount)
|
if (end > totalCount)
|
||||||
{
|
{
|
||||||
end = totalCount;
|
end = totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int index = start; index < end; index++)
|
for (int index = start; index < end; index++)
|
||||||
{
|
{
|
||||||
session.ProcessPrime(filteredPrimes[index]);
|
session.ProcessPrime(filteredPrimes[index]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
session.Dispose();
|
||||||
session.Dispose();
|
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
CancellationToken.None,
|
CancellationToken.None,
|
||||||
TaskCreationOptions.DenyChildAttach,
|
TaskCreationOptions.DenyChildAttach,
|
||||||
@@ -993,20 +987,16 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
{
|
{
|
||||||
DeterministicRandomCpu.Initialize();
|
DeterministicRandomCpu.Initialize();
|
||||||
var session = new MersenneNumberDivisorByDivisorPrimeScanSessionWithHybridOrder(prototypeCopy, markComposite, clearComposite, printResult);
|
var session = new MersenneNumberDivisorByDivisorPrimeScanSessionWithHybridOrder(prototypeCopy, markComposite, clearComposite, printResult);
|
||||||
try
|
|
||||||
|
GpuPrimeWorkLimiter.Acquire();
|
||||||
|
foreach (ulong prime in filteredPrimes)
|
||||||
{
|
{
|
||||||
GpuPrimeWorkLimiter.Acquire();
|
session.ProcessPrime(prime);
|
||||||
foreach (ulong prime in filteredPrimes)
|
|
||||||
{
|
|
||||||
session.ProcessPrime(prime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GpuPrimeWorkLimiter.Release();
|
|
||||||
session.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GpuPrimeWorkLimiter.Release();
|
||||||
|
session.Dispose();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1026,35 +1016,30 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
startGate.Wait();
|
startGate.Wait();
|
||||||
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
|
|
||||||
try
|
GpuPrimeWorkLimiter.Acquire();
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
GpuPrimeWorkLimiter.Acquire();
|
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
||||||
while (true)
|
if (start >= totalCount)
|
||||||
{
|
{
|
||||||
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
break;
|
||||||
if (start >= totalCount)
|
}
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int end = start + partitionSize;
|
int end = start + partitionSize;
|
||||||
if (end > totalCount)
|
if (end > totalCount)
|
||||||
{
|
{
|
||||||
end = totalCount;
|
end = totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int index = start; index < end; index++)
|
for (int index = start; index < end; index++)
|
||||||
{
|
{
|
||||||
session.ProcessPrime(filteredPrimes[index]);
|
session.ProcessPrime(filteredPrimes[index]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
GpuPrimeWorkLimiter.Release();
|
||||||
GpuPrimeWorkLimiter.Release();
|
session.Dispose();
|
||||||
session.Dispose();
|
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
CancellationToken.None,
|
CancellationToken.None,
|
||||||
TaskCreationOptions.DenyChildAttach,
|
TaskCreationOptions.DenyChildAttach,
|
||||||
@@ -1093,20 +1078,16 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
{
|
{
|
||||||
DeterministicRandomCpu.Initialize();
|
DeterministicRandomCpu.Initialize();
|
||||||
var session = new MersenneNumberDivisorByDivisorPrimeScanSessionWithGpuOrder(prototypeCopy, markComposite, clearComposite, printResult);
|
var session = new MersenneNumberDivisorByDivisorPrimeScanSessionWithGpuOrder(prototypeCopy, markComposite, clearComposite, printResult);
|
||||||
try
|
|
||||||
|
GpuPrimeWorkLimiter.Acquire();
|
||||||
|
foreach (ulong prime in filteredPrimes)
|
||||||
{
|
{
|
||||||
GpuPrimeWorkLimiter.Acquire();
|
session.ProcessPrime(prime);
|
||||||
foreach (ulong prime in filteredPrimes)
|
|
||||||
{
|
|
||||||
session.ProcessPrime(prime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GpuPrimeWorkLimiter.Release();
|
|
||||||
session.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GpuPrimeWorkLimiter.Release();
|
||||||
|
session.Dispose();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1126,35 +1107,30 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
startGate.Wait();
|
startGate.Wait();
|
||||||
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
|
|
||||||
try
|
GpuPrimeWorkLimiter.Acquire();
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
GpuPrimeWorkLimiter.Acquire();
|
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
||||||
while (true)
|
if (start >= totalCount)
|
||||||
{
|
{
|
||||||
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
break;
|
||||||
if (start >= totalCount)
|
}
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int end = start + partitionSize;
|
int end = start + partitionSize;
|
||||||
if (end > totalCount)
|
if (end > totalCount)
|
||||||
{
|
{
|
||||||
end = totalCount;
|
end = totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int index = start; index < end; index++)
|
for (int index = start; index < end; index++)
|
||||||
{
|
{
|
||||||
session.ProcessPrime(filteredPrimes[index]);
|
session.ProcessPrime(filteredPrimes[index]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
GpuPrimeWorkLimiter.Release();
|
||||||
GpuPrimeWorkLimiter.Release();
|
session.Dispose();
|
||||||
session.Dispose();
|
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
CancellationToken.None,
|
CancellationToken.None,
|
||||||
TaskCreationOptions.DenyChildAttach,
|
TaskCreationOptions.DenyChildAttach,
|
||||||
@@ -1192,20 +1168,16 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
{
|
{
|
||||||
DeterministicRandomCpu.Initialize();
|
DeterministicRandomCpu.Initialize();
|
||||||
var session = new MersenneNumberDivisorByDivisorGpuPrimeScanSession(prototype, markComposite, clearComposite, printResult);
|
var session = new MersenneNumberDivisorByDivisorGpuPrimeScanSession(prototype, markComposite, clearComposite, printResult);
|
||||||
try
|
|
||||||
|
GpuPrimeWorkLimiter.Acquire();
|
||||||
|
foreach (ulong prime in filteredPrimes)
|
||||||
{
|
{
|
||||||
GpuPrimeWorkLimiter.Acquire();
|
session.ProcessPrime(prime);
|
||||||
foreach (ulong prime in filteredPrimes)
|
|
||||||
{
|
|
||||||
session.ProcessPrime(prime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GpuPrimeWorkLimiter.Release();
|
|
||||||
session.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GpuPrimeWorkLimiter.Release();
|
||||||
|
session.Dispose();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1225,35 +1197,30 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
startGate.Wait();
|
startGate.Wait();
|
||||||
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
Console.WriteLine($"Task started for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
|
|
||||||
try
|
GpuPrimeWorkLimiter.Acquire();
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
GpuPrimeWorkLimiter.Acquire();
|
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
||||||
while (true)
|
if (start >= totalCount)
|
||||||
{
|
{
|
||||||
int start = Interlocked.Add(ref nextIndex, partitionSize) - partitionSize;
|
break;
|
||||||
if (start >= totalCount)
|
}
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int end = start + partitionSize;
|
int end = start + partitionSize;
|
||||||
if (end > totalCount)
|
if (end > totalCount)
|
||||||
{
|
{
|
||||||
end = totalCount;
|
end = totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int index = start; index < end; index++)
|
for (int index = start; index < end; index++)
|
||||||
{
|
{
|
||||||
session.ProcessPrime(filteredPrimes[index]);
|
session.ProcessPrime(filteredPrimes[index]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
GpuPrimeWorkLimiter.Release();
|
||||||
GpuPrimeWorkLimiter.Release();
|
session.Dispose();
|
||||||
session.Dispose();
|
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
||||||
Console.WriteLine($"Task finished for worker {workerIndex.ToString(CultureInfo.InvariantCulture)}");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
CancellationToken.None,
|
CancellationToken.None,
|
||||||
TaskCreationOptions.DenyChildAttach,
|
TaskCreationOptions.DenyChildAttach,
|
||||||
|
|||||||
Reference in new issue
Block a user