From e274bdecf91cb64ba5acfe94ae4f393fc8a91ec6 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 24 Nov 2020 17:16:06 +0100 Subject: [PATCH] Fix start to be a multiple of 3 Signed-off-by: trivernis --- src/kernel_controller/kernel.cl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/kernel_controller/kernel.cl b/src/kernel_controller/kernel.cl index cb998fa..840d988 100644 --- a/src/kernel_controller/kernel.cl +++ b/src/kernel_controller/kernel.cl @@ -22,8 +22,11 @@ __kernel void check_prime(const int LOWER_PRIME_COUNT, __global const int *LOWER break; } } - if (prime && LOWER_PRIMES[LOWER_PRIME_COUNT - 1] < num) { - for (long i = LOWER_PRIMES[LOWER_PRIME_COUNT - 1]; i <= sqrt((double) num); i += 6) { + long start = LOWER_PRIMES[LOWER_PRIME_COUNT - 1]; + start -= start % 3; + + if (prime && start < num) { + for (long i = start; i <= sqrt((double) num); i += 6) { if (num % (i - 2) == 0 || num % (i - 4) == 0) { prime = false; break;