Serialize GPU prime sieve per accelerator
This commit is contained in:
1 parent
ab133d23c1
commit
47e694cdc1
3 files changed
+111
-36
No files matched your search
@@ -36,5 +36,33 @@ public class PrimeTesterIsPrimeTests
|
||||
|
||||
GpuContextPool.ForceCpu = false;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", "Fast")]
|
||||
public void IsPrimeGpu_handles_parallel_calls_for_known_primes()
|
||||
{
|
||||
GpuContextPool.ForceCpu = false;
|
||||
GpuPrimeWorkLimiter.SetLimit(64);
|
||||
PrimeTester.GpuBatchSize = 256_000;
|
||||
|
||||
ulong[] primes = [107UL, 127UL, 521UL, 607UL];
|
||||
var results = new bool[primes.Length];
|
||||
|
||||
var testers = new ThreadLocal<PrimeTester>(() => new PrimeTester(), trackAllValues: true);
|
||||
Parallel.For(0, primes.Length, i =>
|
||||
{
|
||||
results[i] = testers.Value!.IsPrimeGpu(primes[i], CancellationToken.None);
|
||||
});
|
||||
|
||||
results.Should().AllBeEquivalentTo(true);
|
||||
|
||||
Parallel.For(0, Environment.ProcessorCount * 16, _ =>
|
||||
{
|
||||
foreach (ulong prime in primes)
|
||||
{
|
||||
testers.Value!.IsPrimeGpu(prime, CancellationToken.None).Should().BeTrue();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user