1# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3# All Rights reserved. See files LICENSE and NOTICE for details. 4# 5# This file is part of CEED, a collection of benchmarks, miniapps, software 6# libraries and APIs for efficient high-order finite element and spectral 7# element discretizations for exascale applications. For more information and 8# source code availability see http://github.com/ceed. 9# 10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11# a collaborative effort of two U.S. Department of Energy organizations (Office 12# of Science and the National Nuclear Security Administration) responsible for 13# the planning and preparation of a capable exascale ecosystem, including 14# software, applications, hardware, advanced system engineering and early 15# testbed platforms, in support of the nation's exascale computing imperative. 16 17CONFIG ?= config.mk 18-include $(CONFIG) 19 20ifeq (,$(filter-out undefined default,$(origin CC))) 21 CC = gcc 22endif 23ifeq (,$(filter-out undefined default,$(origin CXX))) 24 CXX = g++ 25endif 26ifeq (,$(filter-out undefined default,$(origin FC))) 27 FC = gfortran 28endif 29ifeq (,$(filter-out undefined default,$(origin LINK))) 30 LINK = $(CC) 31endif 32NVCC ?= $(CUDA_DIR)/bin/nvcc 33NVCC_CXX ?= $(CXX) 34 35# ASAN must be left empty if you don't want to use it 36ASAN ?= 37 38LDFLAGS ?= 39UNDERSCORE ?= 1 40 41# MFEM_DIR env variable should point to sibling directory 42ifneq ($(wildcard ../mfem/libmfem.*),) 43 MFEM_DIR ?= ../mfem 44endif 45 46# NEK5K_DIR env variable should point to sibling directory 47ifneq ($(wildcard ../Nek5000/*),) 48 NEK5K_DIR ?= $(abspath ../Nek5000) 49endif 50export NEK5K_DIR 51MPI ?= 1 52 53# CEED_DIR env for NEK5K testing 54export CEED_DIR = $(abspath .) 55 56# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm) 57XSMM_DIR ?= ../libxsmm 58 59# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa) 60OCCA_DIR ?= ../occa 61 62# env variable MAGMA_DIR can be used too 63MAGMA_DIR ?= ../magma 64# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda 65CUDA_DIR ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \ 66 $(shell which nvcc 2> /dev/null))))),/usr/local/cuda) 67 68# Check for PETSc in ../petsc 69ifneq ($(wildcard ../petsc/lib/libpetsc.*),) 70 PETSC_DIR ?= ../petsc 71endif 72 73# Warning: SANTIZ options still don't run with /gpu/occa 74# export LSAN_OPTIONS=suppressions=.asanignore 75AFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 76 77CC_VENDOR := $(firstword $(filter gcc clang,$(shell $(CC) --version))) 78 79cc_check_flag = $(shell $(CC) -E $(1) -x c /dev/null > /dev/null 2>&1 && echo 1) 80MARCHFLAG := -march=native 81MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native) 82MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG)) 83 84OMP_SIMD_FLAG := -fopenmp-simd 85OMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG)) 86 87OPT ?= -O -g $(MARCHFLAG) -ffp-contract=fast $(OMP_SIMD_FLAG) 88CFLAGS ?= -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP 89CXXFLAGS ?= -std=c++11 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP 90NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler "$(OPT)" -Xcompiler -fPIC 91# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately: 92ifneq ($(filter %xlf %xlf_r,$(FC)),) 93 FFLAGS ?= $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD 94else # gfortran/Intel-style options 95 FFLAGS ?= -cpp $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP 96endif 97 98ifeq ($(COVERAGE), 1) 99 CFLAGS += --coverage 100 LDFLAGS += --coverage 101endif 102 103CFLAGS += $(if $(ASAN),$(AFLAGS)) 104FFLAGS += $(if $(ASAN),$(AFLAGS)) 105LDFLAGS += $(if $(ASAN),$(AFLAGS)) 106CPPFLAGS += -I./include 107LDLIBS = -lm 108OBJDIR := build 109LIBDIR := lib 110 111# Installation variables 112prefix ?= /usr/local 113bindir = $(prefix)/bin 114libdir = $(prefix)/lib 115okldir = $(libdir)/okl 116includedir = $(prefix)/include 117pkgconfigdir = $(libdir)/pkgconfig 118INSTALL = install 119INSTALL_PROGRAM = $(INSTALL) 120INSTALL_DATA = $(INSTALL) -m644 121 122# Get number of processors of the machine 123NPROCS := $(shell getconf _NPROCESSORS_ONLN) 124# prepare make options to run in parallel 125MFLAGS := -j $(NPROCS) --warn-undefined-variables \ 126 --no-print-directory --no-keep-going 127 128PYTHON ?= python3 129PROVE ?= prove 130PROVE_OPTS ?= -j $(NPROCS) 131DARWIN := $(filter Darwin,$(shell uname -s)) 132SO_EXT := $(if $(DARWIN),dylib,so) 133 134ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 135libceed := $(LIBDIR)/libceed.$(SO_EXT) 136CEED_LIBS = -lceed 137libceed.c := $(wildcard interface/ceed*.c) 138gallery.c := $(wildcard gallery/*/ceed*.c) 139libceed.c += $(gallery.c) 140libceed_test := $(LIBDIR)/libceed_test.$(SO_EXT) 141libceeds = $(libceed) $(libceed_test) 142BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked 143BACKENDS := $(BACKENDS_BUILTIN) 144 145# Tests 146tests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c)) 147tests.f := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)) 148tests := $(tests.c:tests/%.c=$(OBJDIR)/%) 149ctests := $(tests) 150tests += $(tests.f:tests/%.f90=$(OBJDIR)/%) 151# Examples 152examples.c := $(sort $(wildcard examples/ceed/*.c)) 153examples.f := $(sort $(wildcard examples/ceed/*.f)) 154examples := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%) 155examples += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%) 156# MFEM Examples 157mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp)) 158mfemexamples := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%) 159# Nek5K Examples 160nekexamples := $(OBJDIR)/nek-bps 161# PETSc Examples 162petscexamples.c := $(wildcard examples/petsc/*.c) 163petscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 164# Navier-Stokes Examples 165nsexamples.c := $(sort $(wildcard examples/navier-stokes/*.c)) 166nsexamples := $(nsexamples.c:examples/navier-stokes/%.c=$(OBJDIR)/ns-%) 167 168# Backends/[ref, blocked, template, memcheck, opt, avx, occa, magma] 169ref.c := $(sort $(wildcard backends/ref/*.c)) 170blocked.c := $(sort $(wildcard backends/blocked/*.c)) 171template.c := $(sort $(wildcard backends/template/*.c)) 172ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 173opt.c := $(sort $(wildcard backends/opt/*.c)) 174avx.c := $(sort $(wildcard backends/avx/*.c)) 175xsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 176cuda.c := $(sort $(wildcard backends/cuda/*.c)) 177cuda.cpp := $(sort $(wildcard backends/cuda/*.cpp)) 178cuda.cu := $(sort $(wildcard backends/cuda/*.cu)) 179cuda-reg.c := $(sort $(wildcard backends/cuda-reg/*.c)) 180cuda-reg.cu := $(sort $(wildcard backends/cuda-reg/*.cu)) 181cuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 182cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu)) 183cuda-gen.c := $(sort $(wildcard backends/cuda-gen/*.c)) 184cuda-gen.cpp := $(sort $(wildcard backends/cuda-gen/*.cpp)) 185cuda-gen.cu := $(sort $(wildcard backends/cuda-gen/*.cu)) 186occa.c := $(sort $(wildcard backends/occa/*.c)) 187magma_preprocessor := python backends/magma/gccm.py 188magma_pre_src := $(filter-out %ceed-magma.c %_tmp.c, $(wildcard backends/magma/ceed-*.c)) 189magma_dsrc := $(wildcard backends/magma/magma_d*.c) 190magma_dsrc += backends/magma/ceed-magma.c 191magma_tmp.c := $(magma_pre_src:%.c=%_tmp.c) 192magma_tmp.cu := $(magma_pre_src:%.c=%_cuda.cu) 193magma_allsrc.c := $(magma_dsrc) $(magma_tmp.c) 194magma_allsrc.cu:= $(magma_tmp.cu) backends/magma/magma_devptr.cu 195magma_allsrc.cu+= backends/magma/magma_dbasisApply_grad.cu backends/magma/magma_dbasisApply_interp.cu backends/magma/magma_dbasisApply_weight.cu 196magma_allsrc.cu+= backends/magma/magma_drestrictApply.cu 197 198# Output using the 216-color rules mode 199rule_file = $(notdir $(1)) 200rule_path = $(patsubst %/,%,$(dir $(1))) 201last_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 202ansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 203emacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 204color_out = @if [ -t 1 ]; then \ 205 printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 206 $(1) $(call ansicolor,$(2)) \ 207 $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 208 printf " %10s %s\n" $(1) $(2); fi 209# if TERM=dumb, use it, otherwise switch to the term one 210output = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 211 212# if V is set to non-nil, turn the verbose mode 213quiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 214 215# Cancel built-in and old-fashioned implicit rules which we don't use 216.SUFFIXES: 217 218.SECONDEXPANSION: # to expand $$(@D)/.DIR 219 220.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu) 221 222%/.DIR : 223 @mkdir -p $(@D) 224 @touch $@ 225 226.PRECIOUS: %/.DIR 227 228lib: $(libceed) $(ceed.pc) 229# run 'lib' target in parallel 230par:;@$(MAKE) $(MFLAGS) V=$(V) lib 231backend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found]) 232info: 233 $(info ------------------------------------) 234 $(info CC = $(CC)) 235 $(info CXX = $(CXX)) 236 $(info FC = $(FC)) 237 $(info CPPFLAGS = $(CPPFLAGS)) 238 $(info CFLAGS = $(value CFLAGS)) 239 $(info CXXFLAGS = $(value CXXFLAGS)) 240 $(info FFLAGS = $(value FFLAGS)) 241 $(info NVCCFLAGS = $(value NVCCFLAGS)) 242 $(info LDFLAGS = $(value LDFLAGS)) 243 $(info LDLIBS = $(LDLIBS)) 244 $(info OPT = $(OPT)) 245 $(info AFLAGS = $(AFLAGS)) 246 $(info ASAN = $(or $(ASAN),(empty))) 247 $(info V = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 248 $(info ------------------------------------) 249 $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/memcheck/serial /cpu/sef/memcheck/blocked)) 250 $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked)) 251 $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked)) 252 $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa)) 253 $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,/gpu/magma)) 254 $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 255 $(info ------------------------------------) 256 $(info MFEM_DIR = $(MFEM_DIR)) 257 $(info NEK5K_DIR = $(NEK5K_DIR)) 258 $(info PETSC_DIR = $(PETSC_DIR)) 259 $(info ------------------------------------) 260 $(info prefix = $(prefix)) 261 $(info includedir = $(value includedir)) 262 $(info libdir = $(value libdir)) 263 $(info okldir = $(value okldir)) 264 $(info pkgconfigdir = $(value pkgconfigdir)) 265 $(info ------------------------------------) 266 @true 267info-backends: 268 $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 269.PHONY: lib all par info info-backends 270 271$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 272$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test))) 273 274# Standard Backends 275libceed.c += $(ref.c) 276libceed.c += $(blocked.c) 277libceed.c += $(opt.c) 278 279# Testing Backends 280test_backends.c := $(template.c) 281TEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub 282 283# Memcheck Backend 284MEMCHK_STATUS = Disabled 285MEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 286ifeq ($(MEMCHK),1) 287 MEMCHK_STATUS = Enabled 288 libceed.c += $(ceedmemcheck.c) 289 BACKENDS += /cpu/self/memcheck/serial /cpu/self/memcheck/blocked 290endif 291 292# AVX Backed 293AVX_STATUS = Disabled 294AVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx) 295AVX := $(filter $(AVX_FLAG),$(shell $(CC) $(OPT) -v -E -x c /dev/null 2>&1)) 296ifneq ($(AVX),) 297 AVX_STATUS = Enabled 298 libceed.c += $(avx.c) 299 BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked 300endif 301 302# libXSMM Backends 303ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 304 $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib) 305 $(libceeds) : LDLIBS += -lxsmm -ldl 306 MKL ?= 307 ifeq (,$(MKL)$(MKLROOT)) 308 BLAS_LIB = -lblas 309 else 310 ifneq ($(MKLROOT),) 311 # Some installs put everything inside an intel64 subdirectory, others not 312 MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*))) 313 MKL_LINK = -L$(MKL_LIBDIR) -Wl,-rpath,$(MKL_LIBDIR) 314 endif 315 BLAS_LIB = $(MKL_LINK) -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl 316 endif 317 $(libceeds) : LDLIBS += $(BLAS_LIB) 318 libceed.c += $(xsmm.c) 319 $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 320 BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 321endif 322 323# OCCA Backends 324ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 325 $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 326 $(libceeds) : LDLIBS += -locca 327 libceed.c += $(occa.c) 328 $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include 329 BACKENDS += /cpu/occa /gpu/occa /omp/occa 330endif 331 332# CUDA Backends 333CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 334CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 335CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs 336CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared /gpu/cuda/gen 337ifneq ($(CUDA_LIB_DIR),) 338 $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include 339 $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR)) 340 $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda 341 $(libceeds) : LINK = $(CXX) 342 libceed.c += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) $(cuda-gen.c) 343 libceed.cpp += $(cuda.cpp) $(cuda-gen.cpp) 344 libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) $(cuda-gen.cu) 345 BACKENDS += $(CUDA_BACKENDS) 346endif 347 348# MAGMA Backend 349ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 350 ifneq ($(CUDA_LIB_DIR),) 351 cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 352 omp_link = -fopenmp 353 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 354 magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 355 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 356 $(libceeds) : LDLIBS += $(magma_link) 357 $(tests) $(examples) : LDLIBS += $(magma_link) 358 libceed.c += $(magma_allsrc.c) 359 libceed.cu += $(magma_allsrc.cu) 360 $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 361 $(magma_allsrc.cu:%.cu=$(OBJDIR)/%.o) : CPPFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(MAGMA_DIR)/control -I$(CUDA_DIR)/include 362 BACKENDS += /gpu/magma 363 endif 364endif 365 366export BACKENDS 367 368# Generate magma_tmp.c and magma_cuda.cu from magma.c 369%_tmp.c %_cuda.cu : %.c 370 $(magma_preprocessor) $< 371 372libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) 373$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE) 374$(libceed.o): | info-backends 375$(libceed) : $(libceed.o) | $$(@D)/.DIR 376 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 377 378$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 379 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 380 381$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR 382 $(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<) 383 384$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 385 $(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<) 386 387$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 388 $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 389 390$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 391 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 392 393$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 394 $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 395 396$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 397 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 398 399$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 400 +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 401 MFEM_DIR="$(abspath $(MFEM_DIR))" $* 402 mv examples/mfem/$* $@ 403 404# Note: Multiple Nek files cannot be built in parallel. The '+' here enables 405# this single Nek bps file to be built in parallel with other examples, 406# such as when calling `make prove-all -j2`. 407$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR 408 +$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek 409 mv examples/nek/build/bps $(OBJDIR)/bps 410 cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps 411 412$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 413 +$(MAKE) -C examples/petsc CEED_DIR=`pwd` \ 414 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 415 mv examples/petsc/$* $@ 416 417$(OBJDIR)/ns-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 418 +$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \ 419 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 420 mv examples/navier-stokes/$* $@ 421 422libceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o) 423$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR 424 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 425 426$(examples) : $(libceed) 427$(tests) : $(libceed_test) 428$(tests) : CEED_LIBS = -lceed_test 429$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 430 431run-t% : BACKENDS += $(TEST_BACKENDS) 432run-% : $(OBJDIR)/% 433 @tests/tap.sh $(<:$(OBJDIR)/%=%) 434 435external_examples := \ 436 $(if $(MFEM_DIR),$(mfemexamples)) \ 437 $(if $(PETSC_DIR),$(petscexamples)) \ 438 $(if $(NEK5K_DIR),$(nekexamples)) \ 439 $(if $(PETSC_DIR),$(nsexamples)) 440 441allexamples = $(examples) $(external_examples) 442 443# The test and prove targets can be controlled via pattern searches. The 444# default is to run tests and those examples that have no external dependencies. 445# Examples of finer grained control: 446# 447# make test search='petsc mfem' # PETSc and MFEM examples 448# make prove search='t3' # t3xx series tests 449# make junit search='ex petsc' # core ex* and PETSc tests 450search ?= t ex 451realsearch = $(search:%=%%) 452matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 453 454# Test core libCEED 455test : $(matched:$(OBJDIR)/%=run-%) 456 457# Run test target in parallel 458tst : ;@$(MAKE) $(MFLAGS) V=$(V) test 459# CPU C tests only for backend % 460ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 461 462prove : BACKENDS += $(TEST_BACKENDS) 463prove : $(matched) 464 $(info Testing backends: $(BACKENDS)) 465 $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 466# Run prove target in parallel 467prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 468 469prove-all : 470 +$(MAKE) prove realsearch=% 471 472junit-t% : BACKENDS += $(TEST_BACKENDS) 473junit-% : $(OBJDIR)/% 474 @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 475 476junit : $(matched:$(OBJDIR)/%=junit-%) 477 478all: $(alltests) 479 480examples : $(allexamples) 481ceedexamples : $(examples) 482nekexamples : $(nekexamples) 483mfemexamples : $(mfemexamples) 484petscexamples : $(petscexamples) 485 486# Benchmarks 487allbenchmarks = petsc-bps 488bench_targets = $(addprefix bench-,$(allbenchmarks)) 489.PHONY: $(bench_targets) benchmarks 490$(bench_targets): bench-%: $(OBJDIR)/% 491 cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 492benchmarks: $(bench_targets) 493 494$(ceed.pc) : pkgconfig-prefix = $(abspath .) 495$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 496.INTERMEDIATE : $(OBJDIR)/ceed.pc 497%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 498 @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 499 500OCCA := $(OCCA_DIR)/bin/occa 501OKL_KERNELS := $(wildcard backends/occa/*.okl) 502 503okl-cache : 504 $(OCCA) cache ceed $(OKL_KERNELS) 505 506okl-clear: 507 $(OCCA) clear -y -l ceed 508 509install : $(libceed) $(OBJDIR)/ceed.pc 510 $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 511 "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)")) 512 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 513 $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 514 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 515 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 516 $(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/") 517 518.PHONY : cln clean doxygen doc lib install all print test tst prove prv prove-all junit examples style tidy okl-cache okl-clear info info-backends 519 520cln clean : 521 $(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi* 522 $(MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))" 523 $(MAKE) -C tests/python clean 524 $(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o 525 $(RM) benchmarks/*output.txt 526 527distclean : clean 528 $(RM) -r doc/html $(CONFIG) 529 530DOXYGEN ?= doxygen 531doxygen : 532 $(DOXYGEN) Doxyfile 533 534doc-html doc-latexpdf doc-epub : doc-% : doxygen 535 make -C doc/sphinx $* 536 537doc : doc-html 538 539style : 540 @astyle --options=.astylerc \ 541 $(filter-out include/ceedf.h tests/t320-basis-f.h, \ 542 $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 543 examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch])) 544 545CLANG_TIDY ?= clang-tidy 546%.c.tidy : %.c 547 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c99 548 549tidy : $(libceed.c:%=%.tidy) 550 551print : 552 @echo $(VAR)=$($(VAR)) 553 554print-% : 555 $(info [ variable name]: $*) 556 $(info [ origin]: $(origin $*)) 557 $(info [ flavor]: $(flavor $*)) 558 $(info [ value]: $(value $*)) 559 $(info [expanded value]: $($*)) 560 $(info ) 561 @true 562 563# "make configure" detects any variables passed on the command line or 564# previously set in config.mk, caching them in config.mk as simple 565# (:=) variables. Variables set in config.mk or on the command line 566# take precedence over the defaults provided in the file. Typical 567# usage: 568# 569# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 570# make 571# make prove 572# 573# The values in the file can be updated by passing them on the command 574# line, e.g., 575# 576# make configure CC=/path/to/other/clang 577 578# All variables to consider for caching 579CONFIG_VARS = CC CXX FC NVCC NVCC_CXX \ 580 OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS \ 581 LDFLAGS LDLIBS \ 582 MAGMA_DIR XSMM_DIR CUDA_DIR MFEM_DIR PETSC_DIR NEK5K_DIR 583 584# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS 585# was set on the command line or in config.mk (where it will appear as 586# a simple variable). 587needs_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1)))) 588 589configure : 590 $(file > $(CONFIG)) 591 $(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v))))) 592 @echo "Configuration cached in $(CONFIG):" 593 @cat $(CONFIG) 594 595wheel : 596 docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io quay.io/pypa/manylinux2014_x86_64 python/make-wheels.sh 597 598.PHONY : configure wheel 599 600# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container 601-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)) 602