Merge branch 'codex/optimize-gpu-memory-usage-in-kernels' of https://github.com/mlemanczyk/even-perfect-numbers-scanner into codex/optimize-gpu-memory-usage-in-kernels

This commit is contained in:
mlemanczyk committed 2025-10-25 05:59:55 +02:00
commit 5276d9d27b
3 files changed
+24 -4

No files matched your search

+3 -1
View File
@@ -419,6 +419,7 @@ internal static class Program
if (useByDivisor)
{
int byDivisorPrimeRange = Math.Max(1, _cliArguments.BlockSize);
MersenneNumberDivisorByDivisorTester.Run(
byDivisorCandidates,
_byDivisorTester!,
@@ -427,7 +428,8 @@ internal static class Program
static () => _lastCompositeP = true,
static () => _lastCompositeP = false,
static (candidate, searchedMersenne, detailedCheck, passedAllTests) => CalculationResultHandler.HandleResult(candidate, searchedMersenne, detailedCheck, passedAllTests, _lastCompositeP),
threadCount);
threadCount,
byDivisorPrimeRange);
CalculationResultHandler.FlushBuffer();
CalculationResultHandler.ReleaseOutputBuffer();
@@ -23,7 +23,8 @@ public class MersenneNumberDivisorByDivisorTesterTests
markComposite: () => compositeMarks++,
clearComposite: () => clearedMarks++,
printResult: (prime, searched, detailed, passed) => results.Add((prime, searched, detailed, passed)),
threadCount: 1);
threadCount: 1,
primesPerTask: 2);
tester.ConfiguredMaxPrime.Should().Be(13UL);
compositeMarks.Should().Be(2);
@@ -1,4 +1,5 @@
using System.Buffers;
using System.Collections.Concurrent;
using System.Globalization;
using System.Runtime.InteropServices;
@@ -14,7 +15,8 @@ public static class MersenneNumberDivisorByDivisorTester
Action markComposite,
Action clearComposite,
Action<ulong, bool, bool, bool> printResult,
int threadCount)
int threadCount,
int primesPerTask)
{
if (candidates.Count == 0)
{
@@ -233,6 +235,8 @@ public static class MersenneNumberDivisorByDivisorTester
// workerCount = 1;
// }
int chunkSize = primesPerTask <= 0 ? 1 : primesPerTask;
void ProcessPrime(ulong prime)
{
Console.WriteLine($"Task started {prime}");
@@ -266,7 +270,20 @@ public static class MersenneNumberDivisorByDivisorTester
TaskScheduler = scheduler
};
Parallel.ForEach(filteredPrimes, options, ProcessPrime);
int totalCount = filteredPrimes.Count;
int partitionSize = chunkSize < 1 ? 1 : chunkSize;
if (partitionSize > totalCount)
{
partitionSize = totalCount;
}
Parallel.ForEach(Partitioner.Create(0, totalCount, partitionSize), options, range =>
{
for (int index = range.Item1; index < range.Item2; index++)
{
ProcessPrime(filteredPrimes[index]);
}
});
}
}
}