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