Use OpenMP.

This commit is contained in:
Nicolás Ortega Froysa 2020-05-10 11:13:08 +02:00
parent d3c1cfafa7
commit 6ab76a1e9b
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <omp.h>
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;
}