From f1c9948b07ac04066c2da098e3b11f80a61453f6 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 24 Nov 2020 17:05:33 +0100 Subject: [PATCH] Improve prime check algorithm Signed-off-by: trivernis --- src/kernel_controller/kernel.cl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kernel_controller/kernel.cl b/src/kernel_controller/kernel.cl index 686e36f..cb998fa 100644 --- a/src/kernel_controller/kernel.cl +++ b/src/kernel_controller/kernel.cl @@ -23,8 +23,8 @@ __kernel void check_prime(const int LOWER_PRIME_COUNT, __global const int *LOWER } } if (prime && LOWER_PRIMES[LOWER_PRIME_COUNT - 1] < num) { - for (long i = LOWER_PRIMES[LOWER_PRIME_COUNT - 1]; i <= sqrt((double) num); i += 2) { - if (num % i == 0) { + for (long i = LOWER_PRIMES[LOWER_PRIME_COUNT - 1]; i <= sqrt((double) num); i += 6) { + if (num % (i - 2) == 0 || num % (i - 4) == 0) { prime = false; break; }