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