-
Notifications
You must be signed in to change notification settings - Fork 60
/
makefile
284 lines (248 loc) · 10.7 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
# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
# reserved. See files LICENSE and NOTICE for details.
#
# This file is part of CEED, a collection of benchmarks, miniapps, software
# libraries and APIs for efficient high-order finite element and spectral
# element discretizations for exascale applications. For more information and
# source code availability see http://github.com/ceed.
#
# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
# a collaborative effort of two U.S. Department of Energy organizations (Office
# of Science and the National Nuclear Security Administration) responsible for
# the planning and preparation of a capable exascale ecosystem, including
# software, applications, hardware, advanced system engineering and early
# testbed platforms, in support of the nation's exascale computing imperative.
define LAGHOS_HELP_MSG
Laghos makefile targets:
make
make setup
make setup MFEM_BUILD=pcuda
make status/info
make test
make tests
make checks
make install
make clean
make distclean
make style
Examples:
make setup
Build Laghos third party libraries: HYPRE, METIS and MFEM
(By default MFEM will be compiled in parallel mode, but MFEM_BUILD=pcuda
will allow a parallel CUDA build.)
make -j 4
Build Laghos using the current configuration options from MFEM.
(Laghos requires the MFEM finite element library, and uses its compiler and
linker options in its build process.)
make status
Display information about the current configuration.
make install PREFIX=<dir>
Install the Laghos executable in <dir>.
make clean
Clean the Laghos executable, library and object files.
make distclean
In addition to "make clean", remove the local installation directory and some
run-time generated files.
make style
Format the Laghos C++ source files using the Artistic Style (astyle) settings
from MFEM.
endef
NPROC = $(shell getconf _NPROCESSORS_ONLN)
GOALS = help clean distclean style setup mfem metis hypre
# Default installation location
PREFIX ?= ./bin
INSTALL = /usr/bin/install
# Use the MFEM source, build, or install directory
MFEM_DIR ?= ../mfem
CONFIG_MK = $(MFEM_DIR)/config/config.mk
ifeq ($(wildcard $(CONFIG_MK)),)
CONFIG_MK = $(MFEM_DIR)/share/mfem/config.mk
endif
TEST_MK = $(MFEM_TEST_MK)
# Use the compiler used by MFEM. Get the compiler and the options for compiling
# and linking from MFEM's config.mk. (Skip this if the target does not require
# building.)
MFEM_LIB_FILE = mfem_is_not_built
ifeq (,$(filter $(GOALS),$(MAKECMDGOALS)))
-include $(CONFIG_MK)
ifneq ($(realpath $(MFEM_DIR)),$(MFEM_SOURCE_DIR))
ifneq ($(realpath $(MFEM_DIR)),$(MFEM_INSTALL_DIR))
MFEM_BUILD_DIR := $(MFEM_DIR)
override MFEM_DIR := $(MFEM_SOURCE_DIR)
endif
endif
endif
CXX = $(MFEM_CXX)
CPPFLAGS = $(MFEM_CPPFLAGS)
CXXFLAGS = $(MFEM_CXXFLAGS)
LAGHOS_FLAGS = $(CPPFLAGS) $(CXXFLAGS) $(MFEM_INCFLAGS)
# Extra include dir, needed for now to include headers like "general/forall.hpp"
EXTRA_INC_DIR = $(or $(wildcard $(MFEM_DIR)/include/mfem),$(MFEM_DIR))
CCC = $(strip $(CXX) $(LAGHOS_FLAGS) $(if $(EXTRA_INC_DIR),-I$(EXTRA_INC_DIR)))
LAGHOS_LIBS = $(MFEM_LIBS) $(MFEM_EXT_LIBS)
LIBS = $(strip $(LAGHOS_LIBS) $(LDFLAGS))
SOURCE_FILES = $(sort $(wildcard *.cpp))
HEADER_FILES = $(sort $(wildcard *.hpp))
OBJECT_FILES = $(SOURCE_FILES:.cpp=.o)
# Targets
.PHONY: all clean distclean install status info opt debug test tests style \
clean-build clean-exec clean-tests setup mfem hypre metis
.SUFFIXES: .cpp .o
.cpp.o:
cd $(<D); $(CCC) -c $(<F)
laghos: $(OBJECT_FILES) $(CONFIG_MK) $(MFEM_LIB_FILE)
$(MFEM_CXX) $(MFEM_LINK_FLAGS) -o laghos $(OBJECT_FILES) $(LIBS)
all:;@$(MAKE) -j $(NPROC) laghos
$(OBJECT_FILES): $(HEADER_FILES) $(CONFIG_MK)
# Quick test with specific execution options
MFEM_TESTS = laghos
RUN_MPI_4 = $(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) 4
test: laghos
@$(call mfem-test,$<, $(RUN_MPI_4), Laghos miniapp,\
-p 0 -m data/square01_quad.mesh -rs 3 -tf 0.1)
# Testing: "test" target and mfem-test* variables are defined in MFEM's
# config/test.mk
ifeq (,$(filter $(GOALS),$(MAKECMDGOALS)))
include $(TEST_MK)
endif
# Generate an error message if the MFEM library is not built and exit
$(CONFIG_MK) $(MFEM_LIB_FILE):
$(error The MFEM library is not built)
cln clean: clean-build clean-exec clean-tests
clean-build:
rm -rf laghos *.o *~ *.dSYM
clean-exec:
rm -rf ./results/*
clean-tests:
rm -rf BASELINE.dat RUN.dat RESULTS.dat
distclean: clean
rm -rf bin/
install: laghos
mkdir -p $(PREFIX)
$(INSTALL) -m 750 laghos $(PREFIX)
help:
$(info $(value LAGHOS_HELP_MSG))
@true
status info:
$(info MFEM_DIR = $(MFEM_DIR))
$(info LAGHOS_FLAGS = $(LAGHOS_FLAGS))
$(info LAGHOS_LIBS = $(value LAGHOS_LIBS))
$(info PREFIX = $(PREFIX))
@true
ASTYLE = astyle --options=$(MFEM_DIR)/config/mfem.astylerc
FORMAT_FILES := $(SOURCE_FILES) $(HEADER_FILES)
style:
@if ! $(ASTYLE) $(FORMAT_FILES) | grep Formatted; then\
echo "No source files were changed.";\
fi
# Laghos checks template - Default arguments
ECHO=echo
SED=sed -e
ranks=1
dims=2 3
problems=0 1 2 3 4 5 6 7
OPTS=-cgt 1.e-14 -rs 0 --checks
USE_CUDA := $(MFEM_USE_CUDA:NO=)
optioni=1 2$(if $(USE_CUDA), 3)
options=-fa -pa $(if $(USE_CUDA),-d_cuda) #-d_debug
#optioni = $(shell for i in {1..$(words $(options))}; do echo $$i; done)
# Laghos checks template - Targets
define laghos_checks_template
.PHONY: laghos_$(1)_$(2)_$(3)_$(4)
laghos_$(1)_$(2)_$(3)_$(4): laghos
$(eval name=laghos-x$(4)-p$(1)-$(2)D$(word $(3),$(options)))
$(eval command=$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(4) ./laghos $(OPTS) -p $(1) -dim $(2) $(shell echo $(word $(3),$(options))|$(SED) "s/-/ -/g"|$(SED) "s/_/ /g"))
@$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(4) ./$$< $(OPTS) -p $(1) -dim $(2) $(shell echo $(word $(3),$(options))|$(SED) "s/-/ -/g"|$(SED) "s/_/ /g") > /dev/null 2>&1 && \
$(call COLOR_PRINT,'\033[0;32m',OK,': $(name)\n') || $(call COLOR_PRINT,'\033[1;31m',KO,': $(command)\n');
endef
# Generate all Laghos checks template targets
$(foreach p, $(problems), $(foreach d, $(dims), $(foreach o, $(optioni), $(foreach r, $(ranks),\
$(eval $(call laghos_checks_template,$(p),$(d),$(o),$(r)))))))
# Output info on all Laghos checks template targets
#$(foreach p, $(problems), $(foreach d, $(dims), $(foreach o, $(optioni), $(foreach r, $(ranks),\
# $(info $(call laghos_checks_template,$(p),$(d),$(o),$(r)))))))
checks: laghos
checks: |$(foreach p,$(problems), $(foreach d,$(dims), $(foreach o,$(optioni), $(foreach r,$(ranks), laghos_$(p)_$(d)_$(o)_$(r)))))
1:;@$(MAKE) -j $(NPROC) checks ranks=1
2:;@$(MAKE) -j 8 checks ranks=2
3:;@$(MAKE) -j 4 checks ranks=3
4:;@$(MAKE) -j 2 checks ranks=4
# Laghos run tests
tests:
cat << EOF > RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 0 -dim 2 -rs 3 -tf 0.75 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 21 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 0 -dim 3 -rs 1 -tf 0.75 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 21 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 1 -dim 2 -rs 3 -tf 0.8 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 18 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 1 -dim 3 -rs 2 -tf 0.6 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 18 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 2 -dim 1 -rs 5 -tf 0.2 -fa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 18 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 3 -m data/rectangle01_quad.mesh -rs 2 -tf 3.0 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 18 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 3 -m data/box01_hex.mesh -rs 1 -tf 5.0 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 18 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP) \
./laghos -p 4 -m data/square_gresho.mesh -rs 3 -ok 3 \
-ot 2 -tf 0.62831853 -s 7 -pa -vs 100 | tee RUN.dat
cat RUN.dat | tail -n 21 | head -n 1 | \
awk '{ printf("step = %04d, dt = %s |e| = %.10e\n", $$2, $$8, $$11); }' >> RESULTS.dat
$(shell cat << EOF > BASELINE.dat)
$(shell echo 'step = 0339, dt = 0.000702, |e| = 4.9695537349e+01' >> BASELINE.dat)
$(shell echo 'step = 1041, dt = 0.000121, |e| = 3.3909635545e+03' >> BASELINE.dat)
$(shell echo 'step = 1154, dt = 0.001655, |e| = 4.6303396053e+01' >> BASELINE.dat)
$(shell echo 'step = 0560, dt = 0.002449, |e| = 1.3408616722e+02' >> BASELINE.dat)
$(shell echo 'step = 0413, dt = 0.000470, |e| = 3.2012077410e+01' >> BASELINE.dat)
$(shell echo 'step = 2872, dt = 0.000064, |e| = 5.6547039096e+01' >> BASELINE.dat)
$(shell echo 'step = 0858, dt = 0.000474, |e| = 5.6691500623e+01' >> BASELINE.dat)
$(shell echo 'step = 0776, dt = 0.000045, |e| = 4.0982431726e+02' >> BASELINE.dat)
diff --report-identical-files RESULTS.dat BASELINE.dat
# Setup: download & install third party libraries: HYPRE, METIS & MFEM
HYPRE_URL = https://github.com/hypre-space/hypre/archive/refs/tags
HYPRE_VER = 2.11.2
HYPRE_DIR = hypre
hypre:
@(if [[ ! -e ../$(HYPRE_DIR) ]]; then cd ..; \
wget -nc $(HYPRE_URL)/v$(HYPRE_VER).tar.gz &&\
tar xzvf v$(HYPRE_VER).tar.gz &&\
ln -s hypre-$(HYPRE_VER) $(HYPRE_DIR) &&\
cd $(HYPRE_DIR)/src &&\
./configure --disable-fortran --without-fei CC=mpicc CXX=mpic++ &&\
make -j $(NPROC); else echo "Using existing ../$(HYPRE_DIR)"; fi)
METIS_URL = http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis
METIS_VER = 4.0.3
METIS_DIR = metis-4.0
metis:
@(if [[ ! -e ../$(METIS_DIR) ]]; then cd ..; \
wget -nc $(METIS_URL)/OLD/metis-$(METIS_VER).tar.gz &&\
tar zxvf metis-$(METIS_VER).tar.gz &&\
ln -s metis-$(METIS_VER) $(METIS_DIR) &&\
cd $(METIS_DIR) &&\
make -j $(NPROC) OPTFLAGS="-O2";\
else echo "Using existing ../$(METIS_DIR)"; fi)
MFEM_GIT = https://github.com/mfem/mfem.git
MFEM_BUILD ?= parallel
#MFEM_BUILD ?= pcuda -j CUDA_ARCH=sm_70
mfem: hypre metis
@(if [[ ! -e ../mfem ]]; then cd ..; \
git clone --single-branch --branch master --depth 1 $(MFEM_GIT) &&\
cd mfem &&\
make $(MFEM_BUILD) -j $(NPROC); else echo "Using existing ../mfem"; fi)
setup: mfem