-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
277 lines (214 loc) · 10.1 KB
/
Makefile
File metadata and controls
277 lines (214 loc) · 10.1 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#Some Makefile for CLASS.
#Julien Lesgourgues, 28.11.2011
#Nils Schöneberg, Matteo Lucca, 27.02.2019
MDIR := $(shell pwd)
WRKDIR = $(MDIR)/build
.base:
if ! [ -e $(WRKDIR) ]; then mkdir $(WRKDIR) ; mkdir $(WRKDIR)/lib; fi;
touch build/.base
vpath %.c source:tools:main:test
vpath %.o build
vpath %.opp build
vpath .base build
########################################################
###### LINES TO ADAPT TO YOUR PLATEFORM ################
########################################################
# your C compiler:
#--- GCC (original) ---
CC = gcc
CPP = g++ --std=c++11 -fpermissive -Wno-write-strings
AR = gcc-ar rv
#--- Clang / AOCC ---
# CC = clang
# CPP = clang++ --std=c++11 -fpermissive -Wno-write-strings -Wno-deprecated
# # llvm-ar is required when LTO is enabled (it understands LLVM bitcode);
# AR = llvm-ar rv
# Your python interpreter.
# In order to use Python 3, you can manually
# substitute python3 to python in the line below, or you can simply
# add a compilation option on the terminal command line:
# "PYTHON=python3 make all" (Thanks to Marius Millea for python3 compatibility)
PYTHON ?= python3
# your optimization flag
OPTFLAG = -O3
OPTFLAG += -march=native -mtune=native
OPTFLAG += -fno-math-errno -fno-trapping-math # CLASS does not check for math errors, and these flags allow the compiler to vectorize more code, which can lead to significant speed-ups. See https://gcc.gnu.org/wiki/Vectorization#Floating_Point_Math_Errors for more details.
#--- GCC flags ---
OPTFLAG += -funroll-loops -ftree-vectorize -ftree-slp-vectorize -flto=auto -fPIC
#--- Clang / AOCC flags ---
# -flto=full : whole-program LTO; slower link but best cross-TU optimisation.
# Use this for production (MCMC) builds — link time is irrelevant
# compared to 200 h of runtime.
# -flto=thin : modular LTO; faster link, slightly less aggressive. Good for
# development / iteration cycles.
# OPTFLAG += -funroll-loops -ftree-vectorize -ftree-slp-vectorize -flto=full -fPIC
# your openmp flag (comment for compiling without openmp)
OMPFLAG = -pthread #-fopenmp
#OMPFLAG = -mp -mp=nonuma -mp=allcores -g
#OMPFLAG = -openmp
# all other compilation flags
CCFLAG = -g -fPIC
LDFLAG = -g -fPIC
# DEV-ONLY FLAGS (uncomment for development, but comment out for production runs, as they can significantly slow down the code and increase memory usage)
# CCFLAG += -Wall #for developing only
# CCFLAG += -Wextra #for developing only
# CCFLAG += -Wpedantic #for developing only
# CCFLAG += -Wno-unused-parameter #for developing only
# CCFLAG += -Wno-variadic-macros # CLASS uses too many of them to fix this (pedantic) warning
# Undefined behavior (catches integer overflow, misaligned access, etc.)
# CCFLAG += -fsanitize=undefined
# LDFLAG += -fsanitize=undefined
# Address sanitizer (heap overflow, use-after-free, leaks)
# CCFLAG += -fsanitize=address
# LDFLAG += -fsanitize=address
########################################
# PGO (Profile-Guided Optimisation)
########################################
#
#--- GCC PGO workflow ---
# Step 1: compile with -fprofile-generate, run typical inputs, then
# Step 2: recompile with -fprofile-use.
# GCC Step 1 (instrument):
# OPTFLAG += -fprofile-generate=$(MDIR)/pgo_profiles
# LDFLAG += -fprofile-generate=$(MDIR)/pgo_profiles
# GCC Step 2 (optimise):
OPTFLAG += -fprofile-use=$(MDIR)/pgo_profiles -fprofile-correction
LDFLAG += -fprofile-use=$(MDIR)/pgo_profiles -fprofile-correction
#
#--- Clang / AOCC PGO workflow ---
# Clang uses a 3-step process:
# Step 1: Compile with -fprofile-instr-generate (instruments the binary)
# Step 2: Run typical inputs → produces *.profraw files in $LLVM_PROFILE_FILE
# Step 3: Merge raw profiles:
# llvm-profdata merge -output=pgo_profiles/merged.profdata pgo_profiles/*.profraw
# Step 4: Recompile with -fprofile-instr-use=<merged.profdata>
#
# Clang Step 1 (instrument):
# OPTFLAG += -fprofile-instr-generate=$(MDIR)/pgo_profiles/default_%m_%p.profraw
# LDFLAG += -fprofile-instr-generate=$(MDIR)/pgo_profiles/default_%m_%p.profraw
#
# Clang Step 3+4 (optimise — run after merging profiles):
# OPTFLAG += -fprofile-instr-use=$(MDIR)/pgo_profiles/merged.profdata
# LDFLAG += -fprofile-instr-use=$(MDIR)/pgo_profiles/merged.profdata
# leave blank to compile without HyRec, or put path to HyRec directory
# (with no slash at the end: e.g. "external/RecfastCLASS")
HYREC = external/HyRec2020
RECFAST = external/RecfastCLASS
HEATING = external/heating
HALOFIT = external/Halofit
HMCODE = external/HMcode
########################################################
###### IN PRINCIPLE THE REST SHOULD BE LEFT UNCHANGED ##
########################################################
# pass current working directory to the code
CLASSDIR ?= $(MDIR)
CCFLAG += -D__CLASSDIR__='"$(CLASSDIR)"'
# where to find include files *.h
INCLUDES = -I../include
HEADERFILES = $(wildcard ./include/*.h)
# automatically add external programs if needed. First, initialize to blank.
EXTERNAL =
vpath %.c $(RECFAST)
#CCFLAG += -DRECFAST
INCLUDES += -I../$(RECFAST)
EXTERNAL += wrap_recfast.o
HEADERFILES += $(wildcard ./$(RECFAST)/*.h)
vpath %.c $(HEATING)
#CCFLAG += -DHEATING
INCLUDES += -I../$(HEATING)
EXTERNAL += injection.o noninjection.o
HEADERFILES += $(wildcard ./$(HEATING)/*.h)
# update flags for including HyRec
ifneq ($(HYREC),)
vpath %.c $(HYREC)
CCFLAG += -DHYREC
#LDFLAGS += -DHYREC
INCLUDES += -I../$(HYREC)
EXTERNAL += hyrectools.o helium.o hydrogen.o history.o wrap_hyrec.o energy_injection.o
HEADERFILES += $(wildcard ./$(HYREC)/*.h)
endif
vpath %.c $(HALOFIT)
INCLUDES += -I../$(HALOFIT)
EXTERNAL += halofit.o
HEADERFILES += $(wildcard ./$(HALOFIT)/*.h)
vpath %.c $(HMCODE)
INCLUDES += -I../$(HMCODE)
EXTERNAL += hmcode.opp
HEADERFILES += $(wildcard ./$(HMCODE)/*.h)
%.o: %.c .base $(HEADERFILES)
cd $(WRKDIR);$(CC) $(OPTFLAG) $(OMPFLAG) $(CCFLAG) $(INCLUDES) -c ../$< -o $*.o
%.opp: %.c .base $(HEADERFILES)
cd $(WRKDIR);$(CPP) $(OPTFLAG) $(OMPFLAG) $(CCFLAG) $(INCLUDES) -c ../$< -o $*.opp
TOOLS = growTable.o dei_rkck.o sparse.o evolver_rkck.o evolver_ndf15.o arrays.opp parser.o quadrature.o hyperspherical.opp common.o trigonometric_integrals.o
SOURCE = input.o background.o thermodynamics.o perturbations.opp primordial.opp fourier.o transfer.opp harmonic.opp lensing.opp distortions.o
INPUT = input.o
PRECISION = precision.o
BACKGROUND = background.o
THERMO = thermodynamics.o
PERTURBATIONS = perturbations.o
TRANSFER = transfer.o
PRIMORDIAL = primordial.o
HARMONIC = harmonic.o
FOURIER = fourier.o
LENSING = lensing.o
DISTORTIONS = distortions.o
OUTPUT = output.o
CLASS = class.o
TEST_LOOPS = test_loops.o
TEST_LOOPS_OMP = test_loops_omp.o
TEST_HARMONIC = test_harmonic.o
TEST_TRANSFER = test_transfer.o
TEST_FOURIER = test_fourier.o
TEST_PERTURBATIONS = test_perturbations.o
TEST_THERMODYNAMICS = test_thermodynamics.o
TEST_BACKGROUND = test_background.o
TEST_HYPERSPHERICAL = test_hyperspherical.o
C_TOOLS = $(addprefix tools/, $(addsuffix .c,$(basename $(TOOLS))))
C_SOURCE = $(addprefix source/, $(addsuffix .c,$(basename $(SOURCE) $(OUTPUT))))
C_TEST = $(addprefix test/, $(addsuffix .c,$(basename $(TEST_DEGENERACY) $(TEST_LOOPS) $(TEST_TRANSFER) $(TEST_FOURIER) $(TEST_PERTURBATIONS) $(TEST_THERMODYNAMICS))))
C_MAIN = $(addprefix main/, $(addsuffix .c,$(basename $(CLASS))))
C_ALL = $(C_MAIN) $(C_TOOLS) $(C_SOURCE)
H_ALL = $(addprefix include/, common.h svnversion.h $(addsuffix .h, $(basename $(notdir $(C_ALL)))))
PRE_ALL = cl_ref.pre clt_permille.pre
INI_ALL = explanatory.ini lcdm.ini
MISC_FILES = Makefile CPU psd_FD_single.dat myselection.dat myevolution.dat README bbn/sBBN.dat external_Pk/* cpp
PYTHON_FILES = python/classy.pyx python/setup.py python/cclassy.pxd python/test_class.py
all: class libclass.a classy
libclass.a: $(TOOLS) $(SOURCE) $(EXTERNAL)
$(AR) $@ $(addprefix build/, $(TOOLS) $(SOURCE) $(EXTERNAL))
class: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(CLASS)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o class $(addprefix build/,$(notdir $^)) -lm
test_loops: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_loops_omp: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS_OMP)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_harmonic: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_HARMONIC)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_transfer: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_TRANSFER)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_fourier: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_FOURIER)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_perturbations: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_PERTURBATIONS)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_thermodynamics: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_THERMODYNAMICS)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_background: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_BACKGROUND)
$(CPP) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $@ $(addprefix build/,$(notdir $^)) -lm
test_hyperspherical: $(TOOLS) $(TEST_HYPERSPHERICAL)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o test_hyperspherical $(addprefix build/,$(notdir $^)) -lm
tar: $(C_ALL) $(C_TEST) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
tar czvf class.tar.gz $(C_ALL) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
classy: libclass.a python/classy.pyx python/cclassy.pxd
export CC=$(CC); output=$$($(PYTHON) -m pip install . 2>&1); \
echo "$$output"; \
if echo "$$output" | grep -q "ERROR: Cannot uninstall"; then \
site_packages=$$($(PYTHON) -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())" || $(PYTHON) -c "import site; print(site.getsitepackages()[0])") && \
echo "Cleaning up previous installation in: $$site_packages" && \
rm -rf $$site_packages/classy* && \
$(PYTHON) -m pip install .; \
fi
clean: .base
rm -rf $(WRKDIR);
rm -f libclass.a
rm -f $(MDIR)/python/classy.c
rm -rf $(MDIR)/python/build