-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
171 lines (134 loc) · 5.75 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# This file is part of frobenius-test.
#
# Copyright 2014 Colin Benner
#
# frobenius-test is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# frobenius-test is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with frobenius-test. If not, see <http://www.gnu.org/licenses/>.
#
# Set some flags for the C and C++ compilers
#
PROFILE=
#CC = clang
#CXX = clang
DEBUG_COMMON = -DDEBUG -g -Wall -Wextra -Wno-pointer-arith -Wno-format-notliteral
ifeq ($(CC),clang)
DEBUG = $(DEBUG_COMMON) -Wmost -Weverything
else
DEBUG = $(DEBUG_COMMON)
endif
OPT = -O3 -mtune=native -march=native
CFLAGS = -std=gnu99 $(DEBUG) $(OPT) $(PROFILE)
CXXFLAGS = -std=gnu++98 $(DEBUG) $(OPT) $(PROFILE)
#
# Collections of files to be generated and used as dependencies
#
INT_OBJECTS = miller_rabin_int.o frobenius_int.o helpers_int.o
GMP_OBJECTS = miller_rabin.o frobenius.o helpers.o
UTILS = check_all_params check_all_params_long check_all_small_numbers check_all_small_numbers_long
# Version for testing the GMP version of the QFT
#TEST_OBJECTS = test/main.o test/test_frobenius_long.o \
# test/test_miller_rabin_int.o test/test_miller_rabin_long.o
# Version for testing the long long version of the QFT
TEST_OBJECTS = test/main.o test/test_frobenius_int.o \
test/test_miller_rabin_int.o test/test_miller_rabin_long.o
# Output generated by
ALG_TEX = plots/gmp.tex plots/mr.tex plots/frob.tex plots/prep_gmp.tex plots/prep_mr.tex plots/prep_frob.tex
MULT_TEX = plots/multiplications.tex
MISC_TEX = plots/false_positives.tex plots/small_composites.tex
SET_TEX = plots/primes.tex plots/composites.tex plots/mersenne_numbers.tex \
plots/mersenne_primes.tex plots/prep_primes.tex plots/prep_composites.tex \
plots/prep_mersenne_numbers.tex plots/prep_mersenne_primes.tex
#
# Compilation rules
#
all: benchmark plots $(UTILS)
test: run_tests
./run_tests
# Compile the various programmes
benchmark: $(INT_OBJECTS) $(GMP_OBJECTS) benchmark.o common.o helpers_int.o helpers.o small_primes.o
$(CXX) $(CXXFLAGS) -o $@ $^ -lgmp -lm
benchmark.o: benchmark.cc
$(CXX) $(CXXFLAGS) -c -o $@ $^
# Programmes for testing
check_all_params: check_all_params.o frobenius_int.o helpers_int.o small_primes.o common.o
$(CC) $(CFLAGS) -o $@ $^ -lm
check_all_params_long: check_all_params_long.o frobenius.o helpers.o small_primes.o common.o
$(CC) $(CFLAGS) -o $@ $^ -lm -lgmp
check_all_small_numbers: check_all_small_numbers.o $(INT_OBJECTS) small_primes.o common.o
$(CC) $(CFLAGS) -o $@ $^ -lm
check_all_small_numbers_long: check_all_small_numbers_long.o frobenius.o helpers.o \
helpers_int.o small_primes.o common.o
$(CC) $(CFLAGS) -o $@ $^ -lm -lgmp
#
# Small utilities
#
# Add a columm n-2^k to the raw data
add_epsilon_mod_4: add_epsilon_mod_4.o common.o
$(CC) $(CFLAGS) -o $@ $^ -lgmp
# Find composites that pass the first two steps of the QFT
find_non_smooth_numbers: find_non_smooth_numbers.o small_primes.o
$(CC) $(CFLAGS) -o $@ $^ -lgmp
# Find the smallest prime above 2^k for a given integer k
nextprime: nextprime.o common.o
$(CC) $(CFLAGS) -o $@ $^ -lgmp
#
# Tests
#
run_tests: helpers.o helpers_int.o small_primes.o common.o $(TEST_OBJECTS) test/data/primelist.txt
$(CC) $(CFLAGS) -o $@ helpers.o helpers_int.o small_primes.o common.o $(TEST_OBJECTS) -lm -lcunit -lgmp
# Compile the test code
test/main.o: test/main.c
$(CC) $(CFLAGS) -c -o $@ $^
test/test_miller_rabin_int.o: test/test_miller_rabin_int.c test/test_miller_rabin_int.h \
miller_rabin_int.c helpers_int.c helpers_int.h common.h
$(CC) $(CFLAGS) -c -o $@ test/test_miller_rabin_int.c
test/test_miller_rabin_long.o: test/test_miller_rabin_long.c test/test_miller_rabin_long.h \
miller_rabin.c helpers.c helpers.h common.h
$(CC) $(CFLAGS) -c -o $@ test/test_miller_rabin_long.c
test/test_frobenius_int.o: test/test_frobenius_int.c test/test_frobenius_int.h \
frobenius_int.c helpers_int.c helpers_int.h common.h \
small_primes.c small_primes.h
$(CC) $(CFLAGS) -c -o $@ test/test_frobenius_int.c
test/test_frobenius_long.o: test/test_frobenius_long.c test/test_frobenius_long.h \
frobenius.c helpers.c helpers.h common.h small_primes.c \
small_primes.h
$(CC) $(CFLAGS) -c -o $@ test/test_frobenius_long.c
# Generate a large list of primes for testing using djb's primegen (http://cr.yp.to/primegen.html)
test/data/primelist.txt:
primes 2500000000 3000000000 > test/data/primelist.txt
#
# Plot and analyse
#
plots: $(SET_TEX) $(ALG_TEX) $(MULT_TEX) $(MISC_TEX)
# Process raw data
processed/primes_gmp.csv plots/false_positives.tex: process_timings.jl timings_20140708.csv
julia $^
# Generate the plots
$(SET_TEX): plot_sets.plt processed/primes_gmp.csv
gnuplot plot_sets.plt
$(ALG_TEX): plot_algorithms.plt processed/primes_gmp.csv
gnuplot plot_algorithms.plt
$(MULT_TEX): plot_mults.plt processed/primes_gmp.csv
gnuplot plot_mults.plt
# Generate a short report about the number of small positives encountered when
# testing all the parameters for the odd composites 3 < n < 10000.
plots/small_composites.tex: all_params.log small_composites.template
sh small_composites.sh
# Remove object files and binaries
clean:
-rm *.o test/*.o
-rm run_tests benchmark nextprime find_non_smooth_numbers
-rm check_all_params check_all_params_long
-rm check_all_small_numbers check_all_small_numbers_long
# Run the following targets, even if a file of the same name already exists
.PHONY: all clean test