-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
179 lines (146 loc) · 6.98 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
172
173
174
175
176
177
178
179
# Definitions pertanining to the project
# $D is a directory for data that is generated but should not be discarded
# naively. $T is a temporary directory for object files, generated binaries, and
# intermediate results. $R is the directory where the final summary results are
# kept.
D = $(HOME)/data/median
R = results
T = /tmp/MedianOfNinthers
$(shell mkdir -p $D $R $T)
# Data sizes present in the paper
SIZES = 10000 31620 100000 316220 1000000 3162280 10000000
# Compiler flags for instrumented and fast build
CFLAGS_INSTRUMENTED = -std=c++14 -O3 -DCOUNT_SWAPS -DCOUNT_WASTED_SWAPS -DCOUNT_COMPARISONS
CFLAGS = -std=c++14 -O3 -DNDEBUG -DMEASURE_TIME
# Utils
XPROD = $(foreach a,$1,$(foreach b,$3,$a$2$b))
XPROD3 = $(call XPROD,$1,$2,$(call XPROD,$3,$4,$5))
# Sources (without algos)
CXX_CODE = $(addprefix src/,main.cpp common.h timer.h)
# Algorithms
ALGOS = nth_element median_of_ninthers rnd3pivot ninther bfprt_baseline
# Data sets (synthetic)
SYNTHETIC_DATASETS = m3killer organpipe random random01 rotated sorted
# Benchmark files we're interested in
MK_OUTFILES = MEASUREMENTS_$1 = $(foreach n,$(SIZES),$(foreach a,$(ALGOS),$T/$1_$n_$a.time))
$(foreach d,$(SYNTHETIC_DATASETS),$(eval $(call MK_OUTFILES,$d)))
# Data sets (Google Books)
L = a b c d e f g h i j k l m n o p q r s t u v w x y z
GBOOKS_LANGS = eng fre ger ita rus spa
GBOOKS_CORPORA = $(foreach l,$(GBOOKS_LANGS),googlebooks-$l-all-1gram-20120701)
# All measurement output files
MEASUREMENT_OUTPUTS = $(foreach x,$(SYNTHETIC_DATASETS),$(MEASUREMENTS_$x)) \
$(foreach x,$(call XPROD,$(ALGOS),_,$(GBOOKS_CORPORA)),$T/$x_freq.time)
# Results files will be included in the paper. Change this to affect what
# experiments are run.
DATASETS = $(SYNTHETIC_DATASETS) gbooks_freq
RESULTS = $(addprefix $R/,$(DATASETS))
PLOTS = $(addsuffix .svg,$(addprefix plots/,$(DATASETS)))
###############################################################################
# Targets of interest
###############################################################################
all: $(RESULTS) plots/.done
clean:
latexmk -C
rm -rf $D/*.tmp $R*/* $T*/ $(PLOTS) plots/.done
pristine:
rm -rf $D/ $R/* $T/ $(PLOTS) plots/.done
################################################################################
# Data
################################################################################
.PHONY: data
data: $(foreach x,$(call XPROD,$(SYNTHETIC_DATASETS),_,$(SIZES)),$D/$x.dat) $(foreach c,$(GBOOKS_CORPORA),$D/$c_freq.dat)
$D/googlebooks-%_freq.dat: $D/googlebooks-%.txt
cut -f 2 <$^ | rdmd -O -inline support/binarize.d >$@.tmp
mv $@.tmp $@
$D/googlebooks-%.txt: $(foreach l,$L,$D/googlebooks-%-$l.gz)
gunzip --stdout $^ | rdmd -O -inline support/aggregate_ngrams.d >$@.tmp
mv $@.tmp $@
$D/googlebooks-%.gz:
curl --fail http://storage.googleapis.com/books/ngrams/books/googlebooks-$*.gz >$@.tmp
mv $@.tmp $@
define GENERATE_DATA
$D/$1_%.dat: support/generate.d
rdmd -O -inline support/generate.d --kind=$1 --n=$$* >$$@.tmp
mv $$@.tmp $$@
endef
$(foreach d,$(SYNTHETIC_DATASETS),$(eval $(call GENERATE_DATA,$d)))
################################################################################
# Measurements
################################################################################
.PHONY: measurements $(SYNTHETIC_DATASETS) $(GBOOKS_CORPORA)
measurements: $(SYNTHETIC_DATASETS) $(GBOOKS_CORPORA)
gbooks: $(foreach x,$(call XPROD,$(GBOOKS_CORPORA),_freq_,$(ALGOS)),$T/$x.time)
$(foreach d,$(SYNTHETIC_DATASETS),$(eval \
$d: $(MEASUREMENTS_$d);\
))
define MAKE_MEASUREMENT
$T/%_$1.time: $T/$1 $T/$1_instrumented $D/%.dat
$T/$1 $D/$$*.dat >$T/$$*_$1.tmp
$T/$1_instrumented $D/$$*.dat >>$T/$$*_$1.tmp
mv $T/$$*_$1.tmp $T/$$*_$1.stats
sed -n '/^milliseconds: /s/milliseconds: //p' $T/$$*_$1.stats >$T/$$*_$1.tmp
mv $T/$$*_$1.tmp $$@
sed -n '/^rsd: /s/rsd: //p' $T/$$*_$1.stats >$T/$$*_$1.tmp
mv $T/$$*_$1.tmp $T/$$*_$1.rsd
sed -n '/^comparisons: /s/comparisons: //p' $T/$$*_$1.stats >$T/$$*_$1.tmp
mv $T/$$*_$1.tmp $T/$$*_$1.comps
sed -n '/^max_comparisons: /s/max_comparisons: //p' $T/$$*_$1.stats >$T/$$*_$1.tmp
mv $T/$$*_$1.tmp $T/$$*_$1.max_comps
sed -n '/^swaps: /s/swaps: //p' $T/$$*_$1.stats >$T/$$*_$1.tmp
mv $T/$$*_$1.tmp $T/$$*_$1.swaps
$T/$1: src/$1.cpp $(CXX_CODE)
$(CXX) $(CFLAGS) -o $$@ $$(patsubst %.h,,$$^)
$T/$1_instrumented: src/$1.cpp $(CXX_CODE)
$(CXX) $(CFLAGS_INSTRUMENTED) -o $$@ $$(patsubst %.h,,$$^)
endef
$(foreach a,$(ALGOS),$(eval $(call MAKE_MEASUREMENT,$a)))
################################################################################
# Assemble measurement results
################################################################################
$R/gbooks_freq: gbooks
echo "Corpus" $(foreach a,$(ALGOS), " $a") >$@.tmp
$(foreach l,$(GBOOKS_LANGS),printf "$l " >>$@.tmp && paste $(foreach a,$(ALGOS),$T/googlebooks-$l-all-1gram-20120701_freq_$a.time) >>$@.tmp &&) true
mv $@.tmp $@
echo "Corpus" $(foreach a,$(ALGOS), " $a") >$@.tmp
$(foreach l,$(GBOOKS_LANGS),printf "$l " >>$@.tmp && paste $(foreach a,$(ALGOS),$T/googlebooks-$l-all-1gram-20120701_freq_$a.rsd) >>$@.tmp &&) true
mv $@.tmp $@.rsd
echo "Corpus" $(foreach a,$(ALGOS), " $a") >$@.tmp
$(foreach l,$(GBOOKS_LANGS),printf "$l " >>$@.tmp && paste $(foreach a,$(ALGOS),$T/googlebooks-$l-all-1gram-20120701_freq_$a.comps) >>$@.tmp &&) true
mv $@.tmp $@.comps
echo "Corpus" $(foreach a,$(ALGOS), " $a") >$@.tmp
$(foreach l,$(GBOOKS_LANGS),printf "$l " >>$@.tmp && paste $(foreach a,$(ALGOS),$T/googlebooks-$l-all-1gram-20120701_freq_$a.swaps) >>$@.tmp &&) true
mv $@.tmp $@.swaps
define MAKE_RESULT_FILE
$R/$1: $$(MEASUREMENTS_$1)
echo "Size" $$(foreach a,$$(ALGOS), " $$a") >$$@.tmp
$$(foreach n,$$(SIZES),printf "$$n\t" >>$$@.tmp && paste $$(foreach a,$$(ALGOS),$$T/$1_$$n_$$a.time) >>$$@.tmp &&) true
mv $$@.tmp $$@
# Relative Standard Deviation
echo "Size" $$(foreach a,$$(ALGOS), " $$a") >$$@.tmp
$$(foreach n,$$(SIZES),printf "$$n\t" >>$$@.tmp && paste $$(foreach a,$$(ALGOS),$$T/$1_$$n_$$a.rsd) >>$$@.tmp &&) true
mv $$@.tmp $$@.rsd
# Comparisons
echo "Size" $$(foreach a,$$(ALGOS), " $$a") >$$@.tmp
$$(foreach n,$$(SIZES),printf "$$n\t" >>$$@.tmp && paste $$(foreach a,$$(ALGOS),$$T/$1_$$n_$$a.comps) >>$$@.tmp &&) true
mv $$@.tmp $$@.comps
# Worst-case Comparisons
echo "Size" $$(foreach a,$$(ALGOS), " $$a") >$$@.tmp
$$(foreach n,$$(SIZES),printf "$$n\t" >>$$@.tmp && paste $$(foreach a,$$(ALGOS),$$T/$1_$$n_$$a.max_comps) >>$$@.tmp &&) true
mv $$@.tmp $$@.max_comps
# Swaps
echo "Size" $$(foreach a,$$(ALGOS), " $$a") >$$@.tmp
$$(foreach n,$$(SIZES),printf "$$n\t" >>$$@.tmp && paste $$(foreach a,$$(ALGOS),$$T/$1_$$n_$$a.swaps) >>$$@.tmp &&) true
mv $$@.tmp $$@.swaps
endef
$(foreach a,$(SYNTHETIC_DATASETS),$(eval $(call MAKE_RESULT_FILE,$a)))
################################################################################
# Plots
################################################################################
plots/.done : $(RESULTS)
gnuplot plots.gnuplot
touch $@
# Supplemental dependencies
median_of_ninthers.cpp: median_of_ninthers.h
# Don't delete intermediary files
.SECONDARY: