modified: primes/Makefile

modified:   primes/src/sive.c

 Changes not staged for commit:
	deleted:    gitignore
	deleted:    primes/Makefile
deleted:    primes/src/sive.c
main
ketrptr 2024-12-05 13:16:27 +01:00
parent d5e6bacced
commit ecbbcc1f72
2 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,5 @@
CFALGSD=-Wall -Wextra -g -ggdb CFALGSD=-Wall -Wextra -g -ggdb
CFALGSF=-Wall -Wextra -Ofast -march=native -mtune=native -funroll-all-loops CFALGSF=-Wall -Wextra -O3 -march=native -mtune=native -funroll-all-loops
CC = gcc CC = gcc
fast: src/sive.c fast: src/sive.c

View File

@ -2,6 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
typedef uint64_t WORD; typedef uint64_t WORD;
@ -11,14 +12,16 @@ const BOOL true = ~false;
// const WORD limit = 542; // const WORD limit = 542;
// const WORD limit = 1e2; // const WORD limit = 1e2;
const WORD limit = 1e9; const WORD limit = 1e8;
const WORD nr = 78498; const WORD nr = 78498;
// Sive o Atkins hit wheel // Sive o Atkins hit wheel
const WORD s[] = {1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59}; const WORD s[] = {1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59};
const WORD wheelLen = 16; const WORD wheelLen = 16;
int main() { int sieve() {
clock_t t0 = clock();
BOOL *isPrime = calloc(limit, sizeof(WORD)); BOOL *isPrime = calloc(limit, sizeof(WORD));
assert(isPrime != NULL); assert(isPrime != NULL);
@ -184,6 +187,10 @@ for n² ≤ limit, n ← 60 × w + x where w ∈ {0,1,...}, x ∈ s, n ≥ 7:
} }
printf("\n"); printf("\n");
printf("%lu\n", sum); printf("%lu\n", sum);
clock_t t1 = clock();
clock_t delta = t1 - t0;
printf("clocks: %ld, clocks per sec: %ld, s: %ld ", delta, CLOCKS_PER_SEC,
delta / CLOCKS_PER_SEC);
return 0; return 0;
} }