-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
166 lines (129 loc) · 4.28 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
FTR_COMP := gfortran
C++_COMP := g++
PYTHON_PATH := python3
C_COMP := gcc
FLAGS := -O3 -msse2 -DHAVE_SSE2
C_RAND := utils/SFMT-src-1.5.1/SFMT.c
FORTRAN_RAND := utils/mt19937-64.f95
SRC := ./src
BIN := ./bin
OBJ := ./obj
TMP := ./tmp
dir_guard=@mkdir -p $(@D)
input_file="input_file.tmp"
# DEFAULT INPUT VALUES
v0=0.03
rho=1.0
N_reset=1000
N_steps=500
seed=1234
LANGUAGES = fortran cpp c python
all: $(BIN)/c.exe $(BIN)/fortran.exe $(BIN)/cpp.exe $(BIN)/numba_funcs.so
# all: $(LANGUAGES)
# $(LANGUAGES): %: %.exe
# run_$(LANGUAGES): %: $(LANGUAGES).out
run_cpp: cpp.out
run_c: c.out
run_fortran: fortran.out
run_python: $(TMP)/Python.times
$(BIN)/numba_funcs.so: $(SRC)/numba_functions.py
$(dir_guard)
rm -f numba_funcs*
$(PYTHON_PATH) $^
mv $(SRC)/numba_funcs* $@
$(BIN)/c.exe: $(SRC)/main.c
$(dir_guard)
$(C_COMP) $(FLAGS) $^ $(C_RAND) -DSFMT_MEXP=19937 -o $@ -lm
$(BIN)/cpp.exe: $(SRC)/main.cpp
$(dir_guard)
$(C++_COMP) $(FLAGS) $^ $(C_RAND) -DSFMT_MEXP=19937 -o $@
$(BIN)/fortran.exe: $(SRC)/main.f95 $(OBJ)/subroutines.o $(OBJ)/mt19937-64.o
$(dir_guard)
$(FTR_COMP) $(FLAGS) -J$(OBJ) -o $@ $^
$(OBJ)/subroutines.o: $(SRC)/subroutines.f95 $(OBJ)/mt19937-64.o
$(FTR_COMP) $(FLAGS) -J$(OBJ) -c $(SRC)/subroutines.f95 $(OBJ)/mt19937-64.o -o $@
$(OBJ)/mt19937-64.o: $(FORTRAN_RAND)
$(dir_guard)
$(FTR_COMP) $(FLAGS) -J$(OBJ) -c $(FORTRAN_RAND) -o $@
$(TMP)/Fortran.out: $(BIN)/fortran.exe input.dat
$(dir_guard)
$^ > $@
$(TMP)/C.out: $(BIN)/c.exe input.dat
$(dir_guard)
$^ > $@
$(TMP)/C++.out: $(BIN)/cpp.exe input.dat
$(dir_guard)
$^ > $@
$(TMP)/Python.out: $(SRC)/main.py $(SRC)/python_functions.py input.dat
$(dir_guard)
$(PYTHON_PATH) $< input.dat > $@
$(TMP)/Numba.out: $(SRC)/main.py $(BIN)/numba_funcs.so input.dat
$(dir_guard)
$(PYTHON_PATH) $< input.dat > $@
compare_simulation_results: results.png
results.png: $(TMP)/Fortran.out $(TMP)/C.out $(TMP)/C++.out $(TMP)/Python.out $(TMP)/Numba.out
$(PYTHON_PATH) plot_results.py $^
clean:
rm -fr bin tmp bin obj
$(TMP)/Fortran.times: $(BIN)/fortran.exe Ls.dat
@echo "Fortran" > $@
@while read L; do\
echo -n "\r\tComputing Fortran with size $$L";\
echo "$$L L\n$(v0) v0\n$(rho) rho\n$(N_reset) N_reset\n$(N_steps) N_steps\n$(seed) seed" > $(input_file);\
(/usr/bin/time -f "%e" $< $(input_file) > /dev/null ) 2>> $@;\
done <Ls.dat
@echo
$(TMP)/C++.times: $(BIN)/cpp.exe Ls.dat
@echo "C++" > $@
@while read L; do\
echo -n "\r\tComputing C++ with size $$L";\
echo "$$L L\n$(v0) v0\n$(rho) rho\n$(N_reset) N_reset\n$(N_steps) N_steps\n$(seed) seed" > $(input_file);\
(/usr/bin/time -f "%e" $< $(input_file) > /dev/null ) 2>> $@;\
done <Ls.dat
@echo
$(TMP)/C.times: $(BIN)/c.exe Ls.dat
@echo "C" > $@
@while read L; do\
echo -n "\r\tComputing C with size $$L";\
echo "$$L L\n$(v0) v0\n$(rho) rho\n$(N_reset) N_reset\n$(N_steps) N_steps\n$(seed) seed" > $(input_file);\
(/usr/bin/time -f "%e" $< $(input_file) > /dev/null ) 2>> $@;\
done <Ls.dat
@echo
$(TMP)/Python.times: $(SRC)/main.py Ls.dat
@echo "Python" > $@
@while read L; do\
echo -n "\r\tComputing Python with size $$L";\
echo "$$L L\n$(v0) v0\n$(rho) rho\n$(N_reset) N_reset\n$(N_steps) N_steps\n$(seed) seed" > $(input_file);\
timeout 10s bash -c "(/usr/bin/time -f "%e" $(PYTHON_PATH) $< $(input_file) > /dev/null ) 2>> $@" || echo nan >> $@;\
done <Ls.dat
@echo
$(TMP)/Numba.times: $(SRC)/main.py $(BIN)/numba_funcs.so Ls.dat
@echo "Numba" > $@
@while read L; do\
echo -n "\r\tComputing Numba size $$L";\
echo "$$L L\n$(v0) v0\n$(rho) rho\n$(N_reset) N_reset\n$(N_steps) N_steps\n$(seed) seed" > $(input_file);\
timeout 10s bash -c "(/usr/bin/time -f "%e" $(PYTHON_PATH) $< $(input_file) numba > /dev/null ) 2>> $@" || echo nan >> $@;\
done <Ls.dat
@echo
$(TMP)/Ns.times: Ls.dat
$(dir_guard)
@echo "L N" > $@
@while read L; do\
echo -n "$$L " >> $@;\
echo "$$L*$$L*$(rho)" | bc >> $@;\
done <Ls.dat
times.dat: $(TMP)/Ns.times $(TMP)/Fortran.times $(TMP)/C.times $(TMP)/C++.times $(TMP)/Python.times $(TMP)/Numba.times
paste $^ | column -t > times.dat
times.png: times.dat
echo "Plotting execution times"
$(PYTHON_PATH) plot_times.py $^
time: times.png
times: times.png
# for i in $(seq 0 1023 | tqdm --total 1024); do
# do_something
# done
# or
# for i in $(seq 0 1023); do
# do_something
# echo $i
# done | tqdm --total 1024 >> /dev/null