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