Use atomic flag writes in heuristic trial division

This commit is contained in:
Marek Lemańczyk committed 2025-10-29 20:40:40 +01:00
1 parent 5ac05489c1
commit f9504a6a19
4 files changed
+19 -22

No files matched your search

@@ -68,18 +68,10 @@ internal static class PrimeTesterKernels
results[index] = result;
}
public static void HeuristicTrialDivisionKernel(Index1D index, ArrayView<ulong> divisors, ulong n, ArrayView<byte> resultFlag)
public static void HeuristicTrialDivisionKernel(Index1D index, ArrayView<ulong> divisors, ulong n, ArrayView<int> resultFlag)
{
ulong divisor = divisors[index];
if (divisor <= 1UL)
{
return;
}
if (n % divisor == 0UL)
{
resultFlag[0] = 1;
}
Atomic.Or(ref resultFlag[0], divisor <= 1UL ? 0 : (n % divisor == 0UL ? 1 : 0));
}
public static void SharesFactorKernel(Index1D index, ArrayView<ulong> numbers, ArrayView<byte> results)