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