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 = -ccbin $(CXX) -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 152petscexamples.c := $(wildcard examples/petsc/*.c) 153petscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 154# Navier-Stokes Example 155navierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c)) 156navierstokesexample := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%) 157 158# Backends/[ref, blocked, template, memcheck, opt, avx, occa, magma] 159ref.c := $(sort $(wildcard backends/ref/*.c)) 160blocked.c := $(sort $(wildcard backends/blocked/*.c)) 161template.c := $(sort $(wildcard backends/template/*.c)) 162ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 163opt.c := $(sort $(wildcard backends/opt/*.c)) 164avx.c := $(sort $(wildcard backends/avx/*.c)) 165xsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 166cuda.c := $(sort $(wildcard backends/cuda/*.c)) 167cuda.cpp := $(sort $(wildcard backends/cuda/*.cpp)) 168cuda.cu := $(sort $(wildcard backends/cuda/*.cu)) 169cuda-reg.c := $(sort $(wildcard backends/cuda-reg/*.c)) 170cuda-reg.cu := $(sort $(wildcard backends/cuda-reg/*.cu)) 171cuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 172cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu)) 173cuda-gen.c := $(sort $(wildcard backends/cuda-gen/*.c)) 174cuda-gen.cpp := $(sort $(wildcard backends/cuda-gen/*.cpp)) 175cuda-gen.cu := $(sort $(wildcard backends/cuda-gen/*.cu)) 176occa.c := $(sort $(wildcard backends/occa/*.c)) 177magma_preprocessor := python backends/magma/gccm.py 178magma_pre_src := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c)) 179magma_dsrc := $(wildcard backends/magma/magma_d*.c) 180magma_tmp.c := $(magma_pre_src:%.c=%_tmp.c) 181magma_tmp.cu := $(magma_pre_src:%.c=%_cuda.cu) 182magma_allsrc.c := $(magma_dsrc) $(magma_tmp.c) 183magma_allsrc.cu:= $(magma_tmp.cu) 184 185# Output using the 216-color rules mode 186rule_file = $(notdir $(1)) 187rule_path = $(patsubst %/,%,$(dir $(1))) 188last_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 189ansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 190emacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 191color_out = @if [ -t 1 ]; then \ 192 printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 193 $(1) $(call ansicolor,$(2)) \ 194 $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 195 printf " %10s %s\n" $(1) $(2); fi 196# if TERM=dumb, use it, otherwise switch to the term one 197output = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 198 199# if V is set to non-nil, turn the verbose mode 200quiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 201 202# Cancel built-in and old-fashioned implicit rules which we don't use 203.SUFFIXES: 204 205.SECONDEXPANSION: # to expand $$(@D)/.DIR 206 207.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu) 208 209%/.DIR : 210 @mkdir -p $(@D) 211 @touch $@ 212 213.PRECIOUS: %/.DIR 214 215lib: $(libceed) $(ceed.pc) 216# run 'lib' target in parallel 217par:;@$(MAKE) $(MFLAGS) V=$(V) lib 218backend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found]) 219info: 220 $(info ------------------------------------) 221 $(info CC = $(CC)) 222 $(info CXX = $(CXX)) 223 $(info FC = $(FC)) 224 $(info CPPFLAGS = $(CPPFLAGS)) 225 $(info CFLAGS = $(value CFLAGS)) 226 $(info CXXFLAGS = $(value CXXFLAGS)) 227 $(info FFLAGS = $(value FFLAGS)) 228 $(info NVCCFLAGS = $(value NVCCFLAGS)) 229 $(info LDFLAGS = $(value LDFLAGS)) 230 $(info LDLIBS = $(LDLIBS)) 231 $(info OPT = $(OPT)) 232 $(info AFLAGS = $(AFLAGS)) 233 $(info ASAN = $(or $(ASAN),(empty))) 234 $(info V = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 235 $(info ------------------------------------) 236 $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck)) 237 $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked)) 238 $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked)) 239 $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa)) 240 $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,/gpu/magma)) 241 $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 242 $(info ------------------------------------) 243 $(info MFEM_DIR = $(MFEM_DIR)) 244 $(info NEK5K_DIR = $(NEK5K_DIR)) 245 $(info PETSC_DIR = $(PETSC_DIR)) 246 $(info ------------------------------------) 247 $(info prefix = $(prefix)) 248 $(info includedir = $(value includedir)) 249 $(info libdir = $(value libdir)) 250 $(info okldir = $(value okldir)) 251 $(info pkgconfigdir = $(value pkgconfigdir)) 252 $(info ------------------------------------) 253 @true 254info-backends: 255 $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 256.PHONY: lib all par info info-backends 257 258$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 259$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test))) 260 261# Standard Backends 262libceed.c += $(ref.c) 263libceed.c += $(blocked.c) 264libceed.c += $(opt.c) 265 266# Testing Backends 267test_backends.c := $(template.c) 268TEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub 269 270# Memcheck Backend 271MEMCHK_STATUS = Disabled 272MEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 273ifeq ($(MEMCHK),1) 274 MEMCHK_STATUS = Enabled 275 libceed.c += $(ceedmemcheck.c) 276 BACKENDS += /cpu/self/ref/memcheck 277endif 278 279# AVX Backed 280AVX_STATUS = Disabled 281AVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c ' -mavx') 282ifeq ($(AVX),1) 283 AVX_STATUS = Enabled 284 libceed.c += $(avx.c) 285 BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked 286endif 287 288# libXSMM Backends 289ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 290 $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib) 291 $(libceeds) : LDLIBS += -lxsmm -ldl 292 MKL ?= 0 293 ifneq (0,$(MKL)) 294 BLAS_LIB = -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl 295 else 296 BLAS_LIB = -lblas 297 endif 298 $(libceeds) : LDLIBS += $(BLAS_LIB) 299 libceed.c += $(xsmm.c) 300 $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 301 BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 302endif 303 304# OCCA Backends 305ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 306 $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 307 $(libceeds) : LDLIBS += -locca 308 libceed.c += $(occa.c) 309 $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include 310 BACKENDS += /cpu/occa /gpu/occa /omp/occa 311endif 312 313# CUDA Backends 314CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 315CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 316CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs 317CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared /gpu/cuda/gen 318ifneq ($(CUDA_LIB_DIR),) 319 $(libceeds) : CFLAGS += -I$(CUDA_DIR)/include 320 $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include 321 $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR)) 322 $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda 323 $(libceeds) : LINK = $(CXX) 324 libceed.c += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) $(cuda-gen.c) 325 libceed.cpp += $(cuda.cpp) $(cuda-gen.cpp) 326 libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) $(cuda-gen.cu) 327 BACKENDS += $(CUDA_BACKENDS) 328endif 329 330# MAGMA Backend 331ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 332 ifneq ($(CUDA_LIB_DIR),) 333 cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 334 omp_link = -fopenmp 335 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 336 magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 337 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 338 $(libceeds) : LDLIBS += $(magma_link) 339 $(tests) $(examples) : LDLIBS += $(magma_link) 340 libceed.c += $(magma_allsrc.c) 341 libceed.cu += $(magma_allsrc.cu) 342 $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 343 $(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 344 BACKENDS += /gpu/magma 345 endif 346endif 347 348export BACKENDS 349 350# Generate magma_tmp.c and magma_cuda.cu from magma.c 351%_tmp.c %_cuda.cu : %.c 352 $(magma_preprocessor) $< 353 354libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) 355$(libceed.o): | info-backends 356$(libceed) : $(libceed.o) | $$(@D)/.DIR 357 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 358 359$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 360 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 361 362$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR 363 $(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<) 364 365$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 366 $(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<) 367 368$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 369 $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 370 371$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 372 $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 373 374$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 375 $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 376 377$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 378 $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 379 380$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 381 +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 382 MFEM_DIR="$(abspath $(MFEM_DIR))" $* 383 mv examples/mfem/$* $@ 384 385# Note: Multiple Nek files cannot be built in parallel. The '+' here enables 386# this single Nek bps file to be built in parallel with other examples, 387# such as when calling `make prove-all -j2`. 388$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR 389 +$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek 390 mv examples/nek/build/bps $(OBJDIR)/bps 391 cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps 392 393$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 394 +$(MAKE) -C examples/petsc CEED_DIR=`pwd` \ 395 PETSC_DIR="$(abspath $(PETSC_DIR))" $* 396 mv examples/petsc/$* $@ 397 398$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 399 +$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \ 400 PETSC_DIR="$(abspath $(PETSC_DIR))" $* 401 mv examples/navier-stokes/$* $@ 402 403libceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o) 404$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR 405 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 406 407$(examples) : $(libceed) 408$(tests) : $(libceed_test) 409$(tests) : CEED_LIBS = -lceed_test 410$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 411 412run-t% : BACKENDS += $(TEST_BACKENDS) 413run-% : $(OBJDIR)/% 414 @tests/tap.sh $(<:$(OBJDIR)/%=%) 415 416external_examples := \ 417 $(if $(MFEM_DIR),$(mfemexamples)) \ 418 $(if $(PETSC_DIR),$(petscexamples)) \ 419 $(if $(NEK5K_DIR),$(nekexamples)) 420 421allexamples = $(examples) $(external_examples) 422 423# The test and prove targets can be controlled via pattern searches. The 424# default is to run tests and those examples that have no external dependencies. 425# Examples of finer grained control: 426# 427# make test search='petsc mfem' # PETSc and MFEM examples 428# make prove search='t3' # t3xx series tests 429# make junit search='ex petsc' # core ex* and PETSc tests 430search ?= t ex 431realsearch = $(search:%=%%) 432matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 433 434# Test core libCEED 435test : $(matched:$(OBJDIR)/%=run-%) 436 437# Run test target in parallel 438tst : ;@$(MAKE) $(MFLAGS) V=$(V) test 439# CPU C tests only for backend % 440ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 441 442prove : BACKENDS += $(TEST_BACKENDS) 443prove : $(matched) 444 $(info Testing backends: $(BACKENDS)) 445 $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 446# Run prove target in parallel 447prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 448 449prove-all : 450 +$(MAKE) prove realsearch=% 451 452junit-t% : BACKENDS += $(TEST_BACKENDS) 453junit-% : $(OBJDIR)/% 454 @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 455 456junit : $(matched:$(OBJDIR)/%=junit-%) 457 458all: $(alltests) 459 460examples : $(allexamples) 461ceedexamples : $(examples) 462nekexamples : $(nekexamples) 463mfemexamples : $(mfemexamples) 464petscexamples : $(petscexamples) 465 466# Benchmarks 467allbenchmarks = petsc-bps 468bench_targets = $(addprefix bench-,$(allbenchmarks)) 469.PHONY: $(bench_targets) benchmarks 470$(bench_targets): bench-%: $(OBJDIR)/% 471 cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 472benchmarks: $(bench_targets) 473 474$(ceed.pc) : pkgconfig-prefix = $(abspath .) 475$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 476.INTERMEDIATE : $(OBJDIR)/ceed.pc 477%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 478 @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 479 480OCCA := $(OCCA_DIR)/bin/occa 481OKL_KERNELS := $(wildcard backends/occa/*.okl) 482 483okl-cache : 484 $(OCCA) cache ceed $(OKL_KERNELS) 485 486okl-clear: 487 $(OCCA) clear -y -l ceed 488 489install : $(libceed) $(OBJDIR)/ceed.pc 490 $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 491 "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)")) 492 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 493 $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 494 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 495 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 496 $(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/") 497 498.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 499 500cln clean : 501 $(RM) -r $(OBJDIR) $(LIBDIR) 502 $(MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))" 503 $(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o 504 $(RM) benchmarks/*output.txt 505 506distclean : clean 507 $(RM) -r doc/html config.mk 508 509doc : 510 doxygen Doxyfile 511 512style : 513 @astyle --options=.astylerc \ 514 $(filter-out include/ceedf.h tests/t310-basis-f.h, \ 515 $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 516 examples/*/*.[ch] examples/*/*.[ch]pp)) 517 518CLANG_TIDY ?= clang-tidy 519%.c.tidy : %.c 520 $(CLANG_TIDY) $^ -- $(CPPFLAGS) 521 522tidy : $(libceed.c:%=%.tidy) 523 524print : 525 @echo $(VAR)=$($(VAR)) 526 527print-% : 528 $(info [ variable name]: $*) 529 $(info [ origin]: $(origin $*)) 530 $(info [ value]: $(value $*)) 531 $(info [expanded value]: $($*)) 532 $(info ) 533 @true 534 535# "make configure" will autodetect any variables not passed on the 536# command line, caching the result in config.mk to be used on any 537# subsequent invocations of make. For example, 538# 539# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 540# make 541# make prove 542configure : 543 @: > config.mk 544 @echo "CC = $(CC)" | tee -a config.mk 545 @echo "FC = $(FC)" | tee -a config.mk 546 @echo "NVCC = $(NVCC)" | tee -a config.mk 547 @echo "CFLAGS = $(CFLAGS)" | tee -a config.mk 548 @echo "CPPFLAGS = $(CPPFLAGS)" | tee -a config.mk 549 @echo "FFLAGS = $(FFLAGS)" | tee -a config.mk 550 @echo "LDFLAGS = $(LDFLAGS)" | tee -a config.mk 551 @echo "LDLIBS = $(LDLIBS)" | tee -a config.mk 552 @echo "MAGMA_DIR = $(MAGMA_DIR)" | tee -a config.mk 553 @echo "XSMM_DIR = $(XSMM_DIR)" | tee -a config.mk 554 @echo "CUDA_DIR = $(CUDA_DIR)" | tee -a config.mk 555 @echo "MFEM_DIR = $(MFEM_DIR)" | tee -a config.mk 556 @echo "PETSC_DIR = $(PETSC_DIR)" | tee -a config.mk 557 @echo "NEK5K_DIR = $(NEK5K_DIR)" | tee -a config.mk 558 @echo "Configuration cached in config.mk" 559 560.PHONY : configure 561 562-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d) 563