From a5b68282b3a23b27921d6456efa7c3fb63f3b1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Wed, 1 Feb 2017 23:12:23 +0100 Subject: [PATCH] Cancel if `primes.list[i] >= numRoot'. It has been solved!!! --- src/main.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main.c b/src/main.c index 1582bad..f43d557 100644 --- a/src/main.c +++ b/src/main.c @@ -190,23 +190,18 @@ int main(int argc, char *argv[]) { * number we're analyzing. Also, skip `2' since we're not testing even * numbers. */ - /*for(size_t i = 1; mpz_cmp(primes.list[i], numRoot) <= 0; ++i) { - // If `num' is divisible by a prime then go to the next number - if(mpz_divisible_p(num, primes.list[i]) != 0) { - isPrime = false; - break; - } - }*/ -#pragma omp parallel + #pragma omp parallel { -#pragma omp for + #pragma omp for for(size_t i = 1; i < primes.end; ++i) { - if(mpz_divisible_p(num, primes.list[i])) { -#pragma omp atomic write + if(mpz_cmp(primes.list[i], numRoot) >= 0) { + #pragma omp cancel for + } else if(mpz_divisible_p(num, primes.list[i])) { + #pragma omp atomic write isPrime = false; -#pragma omp cancel for + #pragma omp cancel for } -#pragma omp cancellation point for + #pragma omp cancellation point for } }