-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
445 lines (373 loc) · 12.5 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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# -*- Makefile -*-
#
# Makefile for DynEarthSol3D
#
# Author: Eh Tan <[email protected]>
#
## Execute "make" if making production run. Or "make opt=0 openmp=0" for debugging run.
##
## ndims = 3: 3D code; 2: 2D code
## opt = 1 ~ 3: optimized build; others: debugging build
## openacc = 1: enable OpenACC
## openmp = 1: enable OpenMP
## useadapt = 1: use libadaptivity for mesh optimization during remeshing
## adaptive_time_step = 1: use adaptive time stepping technique
## use_R_S = 1: use Rate - State friction law
## useexo = 1: import a exodusII mesh (e.g., created with Trelis)
ndims = 3
opt = 2
openacc = 0
openmp = 1
nprof = 0
useadapt = 0
usemmg = 0
adaptive_time_step = 0
use_R_S = 0
useexo = 0
ifeq ($(ndims), 2)
useadapt = 0 # libadaptivity is 3d only
useexo = 0 # for now, can import only 3d exo mesh
endif
ifneq ($(adaptive_time_step), 1)
use_R_S = 0 # Rate - State friction law only works with adaptive time stepping technique
endif
## Select C++ compiler and set paths to necessary libraries
ifeq ($(useadapt), 1)
CXX = mpicxx # g++-mp-4.7
CXX_BACKEND = g++
# path to vtk header files, if not in standard system location
VTK_INCLUDE = /opt/local/include/vtk-8.1
# path of vtk library files, if not in standard system location
VTK_LIBS = /opt/local/lib
# flag to link with fortran binding of MPI library
#LIB_MPIFORTRAN = -lmpi_mpifh # OpenMPI 1.10.2. Other possibilities: -lmpifort, -lfmpich, -lmpi_f77
LIB_MPIFORTRAN = -lfmpich # OpenMPI 1.10.2. Other possibilities: -lmpifort, -lfmpich, -lmpi_f77
else
ifeq ($(openacc), 1)
CXX = nvc++
openmp = 0 # force no openmp when using openacc
else
ifeq ($(nprof), 1)
CXX = nvc++
else
CXX = g++
endif
endif
CXX_BACKEND = ${CXX}
endif
## path to cuda's base directory
CUDA_DIR = #/cluster/nvidia/hpc_sdk/Linux_x86_64/21.2/cuda
## path to Boost's base directory, if not in standard system location
BOOST_ROOT_DIR =
########################################################################
## Select compiler and linker flags
## (Usually you won't need to modify anything below)
########################################################################
OSNAME := $(shell uname -s)
BOOST_LDFLAGS = -lboost_program_options
ifdef BOOST_ROOT_DIR
# check existence of stage/ directory
has_stage_dir = $(wildcard $(BOOST_ROOT_DIR)/stage)
ifeq (, $(has_stage_dir))
# no stage dir, BOOST_ROOT_DIR is the installation directory
BOOST_CXXFLAGS = -I$(BOOST_ROOT_DIR)/include
BOOST_LIB_DIR = $(BOOST_ROOT_DIR)/lib
else
# with stage dir, BOOST_ROOT_DIR is the build directory
BOOST_CXXFLAGS = -I$(BOOST_ROOT_DIR)
BOOST_LIB_DIR = $(BOOST_ROOT_DIR)/stage/lib
endif
BOOST_LDFLAGS += -L$(BOOST_LIB_DIR)
ifneq ($(OSNAME), Darwin) # Apple's ld doesn't support -rpath
BOOST_LDFLAGS += -Wl,-rpath=$(BOOST_LIB_DIR)
endif
endif
ifeq ($(useexo), 1)
# path to exodus header files
EXO_INCLUDE = ./seacas/include
# path of exodus library files, if not in standard system location
EXO_LIB_DIR = ./seacas/lib
EXO_CXXFLAGS = -I$(EXO_INCLUDE) -DUSEEXODUS
EXO_LDFLAGS = -L$(EXO_LIB_DIR) -lexodus
ifneq ($(OSNAME), Darwin) # Apple's ld doesn't support -rpath
EXO_LDFLAGS += -Wl,-rpath=$(EXO_LIB_DIR)
endif
endif
ifeq ($(usemmg), 1)
# path to MMG3D header files
MMG_INCLUDE = ./mmg/build/include
# path of MMG3D library files, if not in standard system location
MMG_LIB_DIR = ./mmg/build/lib
MMG_CXXFLAGS = -I$(MMG_INCLUDE) -DUSEMMG
ifeq ($(ndims), 3)
MMG_LDFLAGS = -L$(MMG_LIB_DIR) -lmmg3d
else
MMG_LDFLAGS = -L$(MMG_LIB_DIR) -lmmg2d
endif
ifneq ($(OSNAME), Darwin) # Apple's ld doesn't support -rpath
MMG_LDFLAGS += -Wl,-rpath=$(MMG_LIB_DIR)
endif
endif
ifneq (, $(findstring g++, $(CXX_BACKEND))) # if using any version of g++
CXXFLAGS = -g -std=c++0x
LDFLAGS = -lm
TETGENFLAG = -Wno-unused-but-set-variable -Wno-int-to-pointer-cast
ifeq ($(opt), 1)
CXXFLAGS += -O1
else ifeq ($(opt), 2)
CXXFLAGS += -O2
else ifeq ($(opt), 3) # experimental, use at your own risk :)
CXXFLAGS += -march=native -O3 -ffast-math -funroll-loops
else # debugging flags
CXXFLAGS += -O0 -Wall -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -fbounds-check -ftrapv
endif
ifeq ($(openmp), 1)
CXXFLAGS += -fopenmp
LDFLAGS += -fopenmp -Wl,-rpath=/lib64
endif
ifeq ($(useadapt), 1)
ifdef VTK_INCLUDE
CXXFLAGS += -I$(VTK_INCLUDE)
endif
endif
else ifneq (, $(findstring icpc, $(CXX_BACKEND))) # if using intel compiler, tested with v14
CXXFLAGS = -g -std=c++0x
LDFLAGS = -lm
ifeq ($(opt), 1)
CXXFLAGS += -O1
else ifeq ($(opt), 2)
CXXFLAGS += -O2
else ifeq ($(opt), 3) # experimental, use at your own risk :)
CXXFLAGS += -fast -fast-transcendentals -fp-model fast=2
else # debugging flags
CXXFLAGS += -O0 -check=uninit -check-pointers=rw -check-pointers-dangling=all -fp-trap-all=all
endif
ifeq ($(openmp), 1)
CXXFLAGS += -fopenmp
LDFLAGS += -fopenmp
endif
ifeq ($(useadapt), 1)
ifdef VTK_INCLUDE
CXXFLAGS += -I$(VTK_INCLUDE)
endif
endif
else ifneq (, $(findstring nvc++, $(CXX)))
CXXFLAGS = -mno-fma -Minfo=mp,accel
LDFLAGS =
TETGENFLAGS =
ifeq ($(opt), 1)
CXXFLAGS += -O1
else ifeq ($(opt), 2)
CXXFLAGS += -O2
endif
ifeq ($(openacc), 1)
CXXFLAGS += -acc=gpu -gpu=managed,nofma -Mcuda -DACC
LDFLAGS += -acc=gpu -gpu=managed -Mcuda
endif
ifeq ($(openmp), 1)
CXXFLAGS += -fopenmp
LDFLAGS += -fopenmp
endif
ifeq ($(nprof), 1)
CXXFLAGS += -I$(CUDA_DIR)/include -DUSE_NPROF
LDFLAGS += -L$(CUDA_DIR)/lib64 -Wl,-rpath,$(CUDA_DIR)/lib64 -lnvToolsExt -g
endif
else
# the only way to display the error message in Makefile ...
all:
@echo "Unknown compiler, check the definition of 'CXX' in the Makefile."
@false
endif
## Is git in the path?
HAS_GIT := $(shell git --version 2>/dev/null)
ifneq ($(HAS_GIT),)
## Is this a git repository?
IS_REPO := $(shell git rev-parse --s-inside-work-tree 2>/dev/null)
endif
SRCS = \
barycentric-fn.cxx \
brc-interpolation.cxx \
bc.cxx \
binaryio.cxx \
dynearthsol.cxx \
fields.cxx \
geometry.cxx \
ic.cxx \
ic-read-temp.cxx \
input.cxx \
matprops.cxx \
mesh.cxx \
nn-interpolation.cxx \
output.cxx \
phasechanges.cxx \
remeshing.cxx \
rheology.cxx \
markerset.cxx
INCS = \
array2d.hpp \
barycentric-fn.hpp \
binaryio.hpp \
constants.hpp \
parameters.hpp \
matprops.hpp \
sortindex.hpp \
utils.hpp \
mesh.hpp \
markerset.hpp \
output.hpp
OBJS = $(SRCS:.cxx=.$(ndims)d.o)
EXE = dynearthsol$(ndims)d
## Libraries
TET_SRCS = tetgen/predicates.cxx tetgen/tetgen.cxx
TET_INCS = tetgen/tetgen.h
TET_OBJS = $(TET_SRCS:.cxx=.o)
TRI_SRCS = triangle/triangle.c
TRI_INCS = triangle/triangle.h
TRI_OBJS = $(TRI_SRCS:.c=.o)
M_SRCS = $(TRI_SRCS)
M_INCS = $(TRI_INCS)
M_OBJS = $(TRI_OBJS)
ifeq ($(ndims), 3)
M_SRCS += $(TET_SRCS)
M_INCS += $(TET_INCS)
M_OBJS += $(TET_OBJS)
CXXFLAGS += -DTHREED
endif
ifeq ($(adaptive_time_step), 1)
CXXFLAGS += -DATS
ifeq ($(use_R_S), 1)
CXXFLAGS += -DRS
endif
endif
ifeq ($(useexo), 1)
CXXFLAGS += $(EXO_CXXFLAGS)
LDFLAGS += $(EXO_LDFLAGS)
endif
ifeq ($(usemmg), 1)
CXXFLAGS += $(MMG_CXXFLAGS)
LDFLAGS += $(MMG_LDFLAGS)
endif
C3X3_DIR = 3x3-C
C3X3_LIBNAME = 3x3
ANN_DIR = ann
ANN_LIBNAME = ANN
CXXFLAGS += -I$(ANN_DIR)/include
ifeq ($(useadapt), 1)
LIBADAPTIVITY_DIR = ./libadaptivity
LIBADAPTIVITY_INC = $(LIBADAPTIVITY_DIR)/include
LIBADAPTIVITY_LIB = $(LIBADAPTIVITY_DIR)/lib
LIBADAPTIVITY_LIBNAME = adaptivity
CXXFLAGS += -I$(LIBADAPTIVITY_INC) -DADAPT -DHAVE_VTK=1 \
-I$(LIBADAPTIVITY_DIR)/adapt3d/include -I$(LIBADAPTIVITY_DIR)/metric_field/include \
-I$(LIBADAPTIVITY_DIR)/load_balance/include
endif
## Action
.PHONY: all clean take-snapshot
all: $(EXE) tetgen/tetgen triangle/triangle take-snapshot
ifeq ($(useadapt), 1)
$(LIBADAPTIVITY_DIR)/lflags.mk: $(LIBADAPTIVITY_DIR)/Makefile
@grep '^LFLAGS' $(LIBADAPTIVITY_DIR)/adapt3d/Makefile > $@
$(LIBADAPTIVITY_DIR)/cppflags.mk: $(LIBADAPTIVITY_DIR)/Makefile
@grep '^CPPFLAGS' $(LIBADAPTIVITY_DIR)/adapt3d/Makefile | sed "s:-I./include -I../include::" > $@
$(LIBADAPTIVITY_DIR)/Makefile: $(LIBADAPTIVITY_DIR)/configure
@cd $(LIBADAPTIVITY_DIR) && VTK_INCLUDE=${VTK_INCLUDE} VTK_LIBS=${VTK_LIBS} ./configure --enable-vtk exec_prefix=`pwd`
$(LIBADAPTIVITY_LIB)/libadaptivity.a: $(LIBADAPTIVITY_DIR)/Makefile $(LIBADAPTIVITY_DIR)/lflags.mk $(LIBADAPTIVITY_DIR)/cppflags.mk
@+$(MAKE) -C $(LIBADAPTIVITY_DIR)
-include $(LIBADAPTIVITY_DIR)/lflags.mk
-include $(LIBADAPTIVITY_DIR)/cppflags.mk
LIBADAPTIVITY_LIBS = $(LIBADAPTIVITY_LIB)/libadaptivity.a $(LFLAGS) $(LIB_MPIFORTRAN)
CXXFLAGS += $(CPPFLAGS)
$(EXE): $(M_OBJS) $(C3X3_DIR)/lib$(C3X3_LIBNAME).a $(ANN_DIR)/lib/lib$(ANN_LIBNAME).a $(LIBADAPTIVITY_LIB)/libadaptivity.a $(OBJS)
$(CXX) $(M_OBJS) $(OBJS) $(LDFLAGS) $(BOOST_LDFLAGS) \
-L$(C3X3_DIR) -l$(C3X3_LIBNAME) -L$(ANN_DIR)/lib -l$(ANN_LIBNAME) \
$(LIBADAPTIVITY_LIBS) \
-o $@
ifeq ($(OSNAME), Darwin) # fix for dynamic library problem on Mac
install_name_tool -change libboost_program_options.dylib $(BOOST_LIB_DIR)/libboost_program_options.dylib $@
ifeq ($(useexo), 1) # fix for dynamic library problem on Mac
install_name_tool -change libexodus.dylib $(EXO_LIB_DIR)/libexodus.dylib $@
endif
endif
else # IF useadapt is 0
$(EXE): $(M_OBJS) $(OBJS) $(C3X3_DIR)/lib$(C3X3_LIBNAME).a $(ANN_DIR)/lib/lib$(ANN_LIBNAME).a
$(CXX) $(M_OBJS) $(OBJS) $(LDFLAGS) $(BOOST_LDFLAGS) \
-L$(C3X3_DIR) -l$(C3X3_LIBNAME) -L$(ANN_DIR)/lib -l$(ANN_LIBNAME) \
-o $@
ifeq ($(OSNAME), Darwin) # fix for dynamic library problem on Mac
install_name_tool -change libboost_program_options.dylib $(BOOST_LIB_DIR)/libboost_program_options.dylib $@
ifeq ($(useexo), 1) # fix for dynamic library problem on Mac
install_name_tool -change libexodus.dylib $(EXO_LIB_DIR)/libexodus.dylib $@
endif
ifeq ($(usemmg), 1) # fix for dynamic library problem on Mac
ifeq ($(ndims), 3)
install_name_tool -change libmmg3d.dylib $(MMG_LIB_DIR)/libmmg3d.dylib $@
else
install_name_tool -change libmmg2d.dylib $(MMG_LIB_DIR)/libmmg2d.dylib $@
endif
endif # end of usemmg
endif # end of Darwin
endif # end of useadapt
take-snapshot:
@# snapshot of the code for building the executable
@echo Flags used to compile the code: > snapshot.diff
@echo ' ' CXX=$(CXX) opt=$(opt) openmp=$(openmp) >> snapshot.diff
@echo ' ' CXXFLAGS=$(CXXFLAGS) >> snapshot.diff
@echo ' ' LDFLAGS=$(LDFLAGS) >> snapshot.diff
@echo ' ' PATH=$(PATH) >> snapshot.diff
@echo ' ' LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) >> snapshot.diff
@echo >> snapshot.diff
@echo >> snapshot.diff
ifneq ($(HAS_GIT),)
ifneq ($(IS_REPO),)
@echo '==== Summary of the code ====' >> snapshot.diff
@git show -s >> snapshot.diff
@echo >> snapshot.diff
@echo >> snapshot.diff
@git status >> snapshot.diff
@echo >> snapshot.diff
@echo '== Code modification (not checked-in) ==' >> snapshot.diff
@echo >> snapshot.diff
@git diff >> snapshot.diff
@echo >> snapshot.diff
@echo '== Code modification (checked-in but not in "origin") ==' >> snapshot.diff
@echo >> snapshot.diff
@git log --patch -- origin..HEAD >> snapshot.diff
else
@echo "Warning: Not a git repository. Cannot take code snapshot." | tee -a snapshot.diff
@echo "Warning: Use 'git clone' to copy the code!" | tee -a snapshot.diff
endif
else
@echo "'git' is not in path, cannot take code snapshot." >> snapshot.diff
endif
$(OBJS): %.$(ndims)d.o : %.cxx $(INCS)
$(CXX) $(CXXFLAGS) $(BOOST_CXXFLAGS) -c $< -o $@
$(TRI_OBJS): %.o : %.c $(TRI_INCS)
@# Triangle cannot be compiled with -O2
$(CXX) $(CXXFLAGS) -O1 -DTRILIBRARY -DREDUCED -DANSI_DECLARATORS -c $< -o $@
triangle/triangle: triangle/triangle.c
$(CXX) $(CXXFLAGS) -O1 -DREDUCED -DANSI_DECLARATORS triangle/triangle.c -o $@
tetgen/predicates.o: tetgen/predicates.cxx $(TET_INCS)
@# Compiling J. Shewchuk predicates, should always be
@# equal to -O0 (no optimization). Otherwise, TetGen may not
@# work properly.
$(CXX) $(CXXFLAGS) -DTETLIBRARY -O0 -c $< -o $@
tetgen/tetgen.o: tetgen/tetgen.cxx $(TET_INCS)
$(CXX) $(CXXFLAGS) -DNDEBUG -DTETLIBRARY $(TETGENFLAG) -c $< -o $@
tetgen/tetgen: tetgen/predicates.cxx tetgen/tetgen.cxx
$(CXX) $(CXXFLAGS) -O0 -DNDEBUG $(TETGENFLAG) tetgen/predicates.cxx tetgen/tetgen.cxx -o $@
$(C3X3_DIR)/lib$(C3X3_LIBNAME).a:
@+$(MAKE) -C $(C3X3_DIR) openacc=$(openacc) CUDA_DIR=$(CUDA_DIR)
$(ANN_DIR)/lib/lib$(ANN_LIBNAME).a:
@+$(MAKE) -C $(ANN_DIR) linux-g++
deepclean: cleanadapt
@rm -f $(TET_OBJS) $(TRI_OBJS) $(OBJS) $(EXE)
@+$(MAKE) -C $(C3X3_DIR) clean
cleanall: clean
@rm -f $(TET_OBJS) $(TRI_OBJS) $(OBJS) $(EXE)
@+$(MAKE) -C $(C3X3_DIR) clean
@+$(MAKE) -C $(ANN_DIR) realclean
clean:
@rm -f $(OBJS) $(EXE)
cleanadapt:
@rm -f $(LIBADAPTIVITY_DIR)/lflags.mk $(LIBADAPTIVITY_DIR)/cppflags.mk
@+$(MAKE) -C $(LIBADAPTIVITY_DIR) clean