From 6ab76a1e9bfd072e74b9ac32c7727941639e78e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 10 May 2020 11:13:08 +0200 Subject: [PATCH] Use OpenMP. --- Makefile | 4 ++-- src/main.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c999d3d..0f22c5e 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ CC=gcc DEBUG=0 PREFIX=/usr/local INCFLAGS= -LDFLAGS=-lm +LDFLAGS=-lm -fopenmp DEFS=-DVERSION=\"1.0\" -CFLAGS=$(INCFLAGS) -std=c99 -Wall -Wextra -Wfatal-errors -Werror +CFLAGS=$(INCFLAGS) -std=c99 -Wall -Wextra -Wfatal-errors -Werror -fopenmp HDRS= OBJS=src/main.o diff --git a/src/main.c b/src/main.c index da38087..b0e3a68 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,7 @@ #include #include #include +#include int main(int argc, char *argv[]) { if(argc < 2) @@ -48,11 +49,14 @@ int main(int argc, char *argv[]) { return 1; unsigned long long int test_root = sqrt(test_num); + int not_prime = 0; + + #pragma omp parallel for for(unsigned long long int i = 3; i < test_root; i += 2) { if(test_num % i == 0) - return 1; + not_prime = 1; } - return 0; + return not_prime; }