xref: /libCEED/Makefile (revision 241a4b83dc9c714eb4bcc90729a46be02322143a)
10c784865Scamierjs# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20c784865Scamierjs# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30c784865Scamierjs# All Rights reserved. See files LICENSE and NOTICE for details.
40d9661cdSTzanio#
50d9661cdSTzanio# This file is part of CEED, a collection of benchmarks, miniapps, software
60d9661cdSTzanio# libraries and APIs for efficient high-order finite element and spectral
70d9661cdSTzanio# element discretizations for exascale applications. For more information and
80d9661cdSTzanio# source code availability see http://github.com/ceed.
90d9661cdSTzanio#
100d9661cdSTzanio# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110d9661cdSTzanio# a collaborative effort of two U.S. Department of Energy organizations (Office
120d9661cdSTzanio# of Science and the National Nuclear Security Administration) responsible for
130d9661cdSTzanio# the planning and preparation of a capable exascale ecosystem, including
140d9661cdSTzanio# software, applications, hardware, advanced system engineering and early
150d9661cdSTzanio# testbed platforms, in support of the nation's exascale computing imperative.
160d9661cdSTzanio
171571c99dSValeria Barra-include config.mk
181571c99dSValeria Barra
19dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC)))
206ed738d9SJed Brown  CC = gcc
21dc753d40SJed Brownendif
22*241a4b83SYohannifeq (,$(filter-out undefined default,$(origin CXX)))
23*241a4b83SYohann  CXX = g++
24*241a4b83SYohannendif
25dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC)))
2681c9eb91SStan Tomov  FC = gfortran
27dc753d40SJed Brownendif
28*241a4b83SYohannifeq (,$(filter-out undefined default,$(origin LINK)))
29*241a4b83SYohann  LINK = $(CC)
30*241a4b83SYohannendif
31196a75e4SJed BrownNVCC ?= $(CUDA_DIR)/bin/nvcc
32e86995feScamierjs
333b56482dScamierjs# ASAN must be left empty if you don't want to use it
340a7eccc5ScamierjsASAN ?=
356850bcb5Scamierjs
36e86995feScamierjsLDFLAGS ?=
3732d74c32SThilina RathnayakeUNDERSCORE ?= 1
381b58aefaScamierjs
39f9fa8c39Sjeremylt# MFEM_DIR env variable should point to sibling directory
40bf3e26f6SVeselin Dobrevifneq ($(wildcard ../mfem/libmfem.*),)
419ba53df8Sjeremylt  MFEM_DIR ?= ../mfem
42f9fa8c39Sjeremyltendif
43f9fa8c39Sjeremylt
444d1cd9fcSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory
454d1cd9fcSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),)
4686a4271fSThilina Rathnayake  NEK5K_DIR ?= $(abspath ../Nek5000)
474d1cd9fcSJeremy L Thompsonendif
4886a4271fSThilina Rathnayakeexport NEK5K_DIR
4986a4271fSThilina RathnayakeMPI ?= 1
5086a4271fSThilina Rathnayake
5186a4271fSThilina Rathnayake# CEED_DIR env for NEK5K testing
5286a4271fSThilina Rathnayakeexport CEED_DIR = $(abspath .)
534d1cd9fcSJeremy L Thompson
548d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
558d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
568d713cf6Sjeremylt
5712123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
587f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa
59f797d7b2Scamierjs
605a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too
615a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma
625a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda
635a9ca9adSVeselin DobrevCUDA_DIR  ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \
645a9ca9adSVeselin Dobrev               $(shell which nvcc 2> /dev/null))))),/usr/local/cuda)
6582b77998SStan Tomov
662f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc
672f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
682f4d9adbSJeremy L Thompson  PETSC_DIR ?= ../petsc
692f4d9adbSJeremy L Thompsonendif
702f4d9adbSJeremy L Thompson
71bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
7212123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
73c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
7432d74c32SThilina Rathnayake
752774d5cbSJeremy L ThompsonOPT    = -O -g -march=native -ffp-contract=fast -fopenmp-simd
76323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
77*241a4b83SYohannCXXFLAGS = $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
789f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC
791dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately:
801dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),)
8110da579bSJeremy L Thompson  FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD
82323c739cSJed Brownelse # gfortran/Intel-style options
838980d4a7Sjeremylt  FFLAGS = -cpp     $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP
841dc2661bSVeselin Dobrevendif
851b58aefaScamierjs
8632d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1)
8732d74c32SThilina Rathnayake  CFLAGS += -DUNDERSCORE
8832d74c32SThilina Rathnayakeendif
8932d74c32SThilina Rathnayake
90a6f4783aSJed Brownifeq ($(COVERAGE), 1)
91a6f4783aSJed Brown  CFLAGS += --coverage
92a6f4783aSJed Brown  LDFLAGS += --coverage
93a6f4783aSJed Brownendif
94a6f4783aSJed Brown
954dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
964dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
974dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS))
986ea7c6c1SJed BrownCPPFLAGS = -I./include
99582447c9SJed BrownLDLIBS = -lm
10091b7489eSJed BrownOBJDIR := build
1016ea7c6c1SJed BrownLIBDIR := lib
1026ea7c6c1SJed Brown
103d5217624SJed Brown# Installation variables
104d5217624SJed Brownprefix ?= /usr/local
105d5217624SJed Brownbindir = $(prefix)/bin
106d5217624SJed Brownlibdir = $(prefix)/lib
107bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl
108d5217624SJed Brownincludedir = $(prefix)/include
109d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
110d5217624SJed BrownINSTALL = install
111d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
112d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
113d5217624SJed Brown
1143b56482dScamierjs# Get number of processors of the machine
11569762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
1163b56482dScamierjs# prepare make options to run in parallel
11782985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
11821ae6867Scamierjs                       --no-print-directory --no-keep-going
11987e762eaSJed Brown
1208ec9d54bSJed BrownPYTHON ?= python3
121bfa078e6SJed BrownPROVE ?= prove
1223a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
1235c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
1245c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1259df38c42SVeselin Dobrev
1266ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
12791b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT)
1287e68d260SJed BrownCEED_LIBS = -lceed
129d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c)
130265be9c8Sjeremyltlibceed_test := $(LIBDIR)/libceed_test.$(SO_EXT)
13176af460cSJed Brownlibceeds = $(libceed) $(libceed_test)
132265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
133d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN)
134bf000209STzanio
135bf000209STzanio# Tests
13657c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
1378980d4a7Sjeremylttests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))
13891b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
1393f3e7340Scamierjsctests    := $(tests)
1408980d4a7Sjeremylttests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
14186a4271fSThilina Rathnayake# Examples
142182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
143182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f))
144182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
145182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
14686a4271fSThilina Rathnayake# MFEM Examples
1472158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
14816c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
14986a4271fSThilina Rathnayake# Nek5K Examples
15086a4271fSThilina Rathnayakenekexamples  := $(OBJDIR)/nek-bps
15186a4271fSThilina Rathnayake# PETSc Examples
152e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c))
153e797ab98SJed Brownpetscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
15486a4271fSThilina Rathnayake# Navier-Stokes Example
1552774d5cbSJeremy L Thompsonnavierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c))
1562774d5cbSJeremy L Thompsonnavierstokesexample  := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%)
157e797ab98SJed Brown
15886a4271fSThilina Rathnayake# Backends/[ref, blocked, template, memcheck, opt, avx, occa, magma]
159ae3cba82Scamierjsref.c          := $(sort $(wildcard backends/ref/*.c))
16089c6efa4Sjeremyltblocked.c      := $(sort $(wildcard backends/blocked/*.c))
161a718229cSjeremylttemplate.c     := $(sort $(wildcard backends/template/*.c))
16289c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
16389c6efa4Sjeremyltopt.c          := $(sort $(wildcard backends/opt/*.c))
16489c6efa4Sjeremyltavx.c          := $(sort $(wildcard backends/avx/*.c))
16589c6efa4Sjeremyltxsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
1669f0427d9SYohanncuda.c         := $(sort $(wildcard backends/cuda/*.c))
1679f0427d9SYohanncuda.cu        := $(sort $(wildcard backends/cuda/*.cu))
16855ae60f9SYohanncuda-reg.c     := $(sort $(wildcard backends/cuda-reg/*.c))
16955ae60f9SYohanncuda-reg.cu    := $(sort $(wildcard backends/cuda-reg/*.cu))
170c532df63SYohanncuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
171c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu))
172*241a4b83SYohanncuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
173*241a4b83SYohanncuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
174*241a4b83SYohanncuda-gen.cu    := $(sort $(wildcard backends/cuda-gen/*.cu))
175ae3cba82Scamierjsocca.c         := $(sort $(wildcard backends/occa/*.c))
176755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py
177c4acb06bSStan Tomovmagma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
178c4acb06bSStan Tomovmagma_dsrc     := $(wildcard backends/magma/magma_d*.c)
179c4acb06bSStan Tomovmagma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
180c4acb06bSStan Tomovmagma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
181c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
182c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu)
18382985883Scamierjs
1849bdc3d68Scamierjs# Output using the 216-color rules mode
18518a724fcScamierjsrule_file = $(notdir $(1))
18618a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1)))
18718a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
1883c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
189abb87f81Scamierjsemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
190abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \
19118a724fcScamierjs				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
1923c5d0cdfSJed Brown					$(1) $(call ansicolor,$(2)) \
19318a724fcScamierjs					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
19418a724fcScamierjs				printf "  %10s %s\n" $(1) $(2); fi
195f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one
196abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
19782985883Scamierjs
1989bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode
19918a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
20021ae6867Scamierjs
201da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
2029df38c42SVeselin Dobrev.SUFFIXES:
203da72e7fcSJed Brown
20491b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
2059df38c42SVeselin Dobrev
206c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
20714c1ded1SStan Tomov
20891b7489eSJed Brown%/.DIR :
20991b7489eSJed Brown	@mkdir -p $(@D)
21091b7489eSJed Brown	@touch $@
21191b7489eSJed Brown
21291b7489eSJed Brown.PRECIOUS: %/.DIR
21391b7489eSJed Brown
21423072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
21523072ed2SVeselin Dobrev# run 'lib' target in parallel
2162f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
217d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
218bf3e26f6SVeselin Dobrevinfo:
219bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
220bf3e26f6SVeselin Dobrev	$(info CC            = $(CC))
221*241a4b83SYohann	$(info CXX           = $(CXX))
222bf3e26f6SVeselin Dobrev	$(info FC            = $(FC))
223bf3e26f6SVeselin Dobrev	$(info CPPFLAGS      = $(CPPFLAGS))
224bf3e26f6SVeselin Dobrev	$(info CFLAGS        = $(value CFLAGS))
225*241a4b83SYohann	$(info CXXFLAGS      = $(value CXXFLAGS))
226bf3e26f6SVeselin Dobrev	$(info FFLAGS        = $(value FFLAGS))
227bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS     = $(value NVCCFLAGS))
228bf3e26f6SVeselin Dobrev	$(info LDFLAGS       = $(value LDFLAGS))
229bf3e26f6SVeselin Dobrev	$(info LDLIBS        = $(LDLIBS))
230bf3e26f6SVeselin Dobrev	$(info OPT           = $(OPT))
231bf3e26f6SVeselin Dobrev	$(info AFLAGS        = $(AFLAGS))
232bf3e26f6SVeselin Dobrev	$(info ASAN          = $(or $(ASAN),(empty)))
233bf3e26f6SVeselin Dobrev	$(info V             = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
234bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
235bdc3149dSjeremylt	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck))
23684a01de5SJeremy L Thompson	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked))
23784a01de5SJeremy L Thompson	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked))
238d20f937dSJed Brown	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
239d20f937dSJed Brown	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
240ab9cabdeSVeselin Dobrev	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
241bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
242bf3e26f6SVeselin Dobrev	$(info MFEM_DIR      = $(MFEM_DIR))
2434d1cd9fcSJeremy L Thompson	$(info NEK5K_DIR     = $(NEK5K_DIR))
244bf3e26f6SVeselin Dobrev	$(info PETSC_DIR     = $(PETSC_DIR))
245bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
246bf3e26f6SVeselin Dobrev	$(info prefix        = $(prefix))
247bf3e26f6SVeselin Dobrev	$(info includedir    = $(value includedir))
248bf3e26f6SVeselin Dobrev	$(info libdir        = $(value libdir))
249bf3e26f6SVeselin Dobrev	$(info okldir        = $(value okldir))
250bf3e26f6SVeselin Dobrev	$(info pkgconfigdir  = $(value pkgconfigdir))
251bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
252bf3e26f6SVeselin Dobrev	@true
25323072ed2SVeselin Dobrevinfo-backends:
254d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
2552f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends
2560e439e50SJed Brown
25724d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
25876af460cSJed Brown$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test)))
25969762e1fScamierjs
26048fffa06Sjeremylt# Standard Backends
26187174f08SJed Brownlibceed.c += $(ref.c)
2624a2e7687Sjeremyltlibceed.c += $(blocked.c)
26389c6efa4Sjeremyltlibceed.c += $(opt.c)
26423072ed2SVeselin Dobrev
265265be9c8Sjeremylt# Testing Backends
266265be9c8Sjeremylttest_backends.c := $(template.c)
267265be9c8SjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
268265be9c8Sjeremylt
269fc7cf9a0Sjeremylt# Memcheck Backend
270bdc3149dSjeremyltMEMCHK_STATUS = Disabled
271b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
272bdc3149dSjeremyltifeq ($(MEMCHK),1)
273bdc3149dSjeremylt  MEMCHK_STATUS = Enabled
274fc7cf9a0Sjeremylt  libceed.c += $(ceedmemcheck.c)
275fc7cf9a0Sjeremylt  BACKENDS += /cpu/self/ref/memcheck
276fc7cf9a0Sjeremyltendif
277fc7cf9a0Sjeremylt
27848fffa06Sjeremylt# AVX Backed
27948fffa06SjeremyltAVX_STATUS = Disabled
28077538c7aSJed BrownAVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c ' -mavx')
28148fffa06Sjeremyltifeq ($(AVX),1)
28248fffa06Sjeremylt  AVX_STATUS = Enabled
28348fffa06Sjeremylt  libceed.c += $(avx.c)
28484a01de5SJeremy L Thompson  BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked
28548fffa06Sjeremyltendif
28648fffa06Sjeremylt
2878d713cf6Sjeremylt# libXSMM Backends
2888d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
28976af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
29076af460cSJed Brown  $(libceeds) : LDLIBS += -lxsmm -ldl
291724a7164Sjeremylt  MKL ?= 0
292724a7164Sjeremylt  ifneq (0,$(MKL))
293c0ea1048SJed Brown    BLAS_LIB = -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
294724a7164Sjeremylt  else
295c0ea1048SJed Brown    BLAS_LIB = -lblas
296724a7164Sjeremylt  endif
297c0ea1048SJed Brown  $(libceeds) : LDLIBS += $(BLAS_LIB)
2988d713cf6Sjeremylt  libceed.c += $(xsmm.c)
299683faae0SJed Brown  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
3008d713cf6Sjeremylt  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
3018d713cf6Sjeremyltendif
3028d713cf6Sjeremylt
30348fffa06Sjeremylt# OCCA Backends
3047f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
30576af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
30676af460cSJed Brown  $(libceeds) : LDLIBS += -locca
30787174f08SJed Brown  libceed.c += $(occa.c)
308683faae0SJed Brown  $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include
309a953af89SJed Brown  BACKENDS += /cpu/occa /gpu/occa /omp/occa
31021ae6867Scamierjsendif
31123072ed2SVeselin Dobrev
31286a4271fSThilina Rathnayake# CUDA Backends
3135a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
3145a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
3153dd0010eSvaleriabarraCUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
316*241a4b83SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared /gpu/cuda/gen
3175a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
318*241a4b83SYohann  $(libceeds) : CFLAGS += -I$(CUDA_DIR)/include
3199d77422eSJed Brown  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
32076af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
32176af460cSJed Brown  $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda
322*241a4b83SYohann  $(libceeds) : LINK = $(CXX)
323*241a4b83SYohann  libceed.c   += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) $(cuda-gen.c)
324*241a4b83SYohann  libceed.cpp += $(cuda-gen.cpp)
325*241a4b83SYohann  libceed.cu  += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) $(cuda-gen.cu)
326ab9cabdeSVeselin Dobrev  BACKENDS += $(CUDA_BACKENDS)
3279f0427d9SYohannendif
3289f0427d9SYohann
3299f0427d9SYohann# MAGMA Backend
3309f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
3319f0427d9SYohann  ifneq ($(CUDA_LIB_DIR),)
3321dc2661bSVeselin Dobrev  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
3331dc2661bSVeselin Dobrev  omp_link = -fopenmp
3341dc2661bSVeselin Dobrev  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
3357692a9b0SVeselin Dobrev  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
3367692a9b0SVeselin Dobrev  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
33776af460cSJed Brown  $(libceeds)           : LDLIBS += $(magma_link)
3387692a9b0SVeselin Dobrev  $(tests) $(examples) : LDLIBS += $(magma_link)
339c4acb06bSStan Tomov  libceed.c  += $(magma_allsrc.c)
340c4acb06bSStan Tomov  libceed.cu += $(magma_allsrc.cu)
341683faae0SJed Brown  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
342c4acb06bSStan Tomov  $(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
343ce41f623SJed Brown  BACKENDS += /gpu/magma
34482b77998SStan Tomov  endif
3455a9ca9adSVeselin Dobrevendif
346755585ceSStan Tomov
347ce41f623SJed Brownexport BACKENDS
348ce41f623SJed Brown
34986a4271fSThilina Rathnayake# Generate magma_tmp.c and magma_cuda.cu from magma.c
35029715310SJed Brown%_tmp.c %_cuda.cu : %.c
351755585ceSStan Tomov	$(magma_preprocessor) $<
352755585ceSStan Tomov
353*241a4b83SYohannlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
35423072ed2SVeselin Dobrev$(libceed.o): | info-backends
35523072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR
356*241a4b83SYohann	$(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
35791b7489eSJed Brown
35858e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
359b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
360ae3cba82Scamierjs
361*241a4b83SYohann$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
362*241a4b83SYohann	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
363*241a4b83SYohann
36458e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
365755585ceSStan Tomov	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
366755585ceSStan Tomov
367b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
368265be9c8Sjeremylt	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
36978b5556aScamierjs
3708980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
371265be9c8Sjeremylt	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
37232d74c32SThilina Rathnayake
373182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
374265be9c8Sjeremylt	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
37591b7489eSJed Brown
376182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
377265be9c8Sjeremylt	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
378673d494eSThilina Rathnayake
37916c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
380c4216f28SJed Brown	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
3812f4d9adbSJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
38216c6c054SJed Brown	mv examples/mfem/$* $@
38316c6c054SJed Brown
38486a4271fSThilina Rathnayake# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
38586a4271fSThilina Rathnayake#       this single Nek bps file to be built in parallel with other examples,
38686a4271fSThilina Rathnayake#       such as when calling `make prove-all -j2`.
38786a4271fSThilina Rathnayake$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
38886a4271fSThilina Rathnayake	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
38986a4271fSThilina Rathnayake	mv examples/nek/build/bps $(OBJDIR)/bps
39086a4271fSThilina Rathnayake	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
39186a4271fSThilina Rathnayake
3927f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
393c4216f28SJed Brown	+$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
3942f4d9adbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
395e797ab98SJed Brown	mv examples/petsc/$* $@
396e797ab98SJed Brown
3972774d5cbSJeremy L Thompson$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
398c4216f28SJed Brown	+$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \
3992774d5cbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
4002774d5cbSJeremy L Thompson	mv examples/navier-stokes/$* $@
4012774d5cbSJeremy L Thompson
402567e4d0aSJed Brownlibceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o)
40376af460cSJed Brown$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR
404*241a4b83SYohann	$(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
405265be9c8Sjeremylt
406265be9c8Sjeremylt$(examples) : $(libceed)
40776af460cSJed Brown$(tests) : $(libceed_test)
40876af460cSJed Brown$(tests) : CEED_LIBS = -lceed_test
409fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
4104859b599SJed Brown
411686de4acSJed Brownrun-t% : BACKENDS += $(TEST_BACKENDS)
412dad465e7SJed Brownrun-% : $(OBJDIR)/%
413d1f7f8d3SJed Brown	@tests/tap.sh $(<:$(OBJDIR)/%=%)
414686de4acSJed Brown
415686de4acSJed Brownexternal_examples := \
416686de4acSJed Brown	$(if $(MFEM_DIR),$(mfemexamples)) \
417686de4acSJed Brown	$(if $(PETSC_DIR),$(petscexamples)) \
418686de4acSJed Brown	$(if $(NEK5K_DIR),$(nekexamples))
419686de4acSJed Brown
420686de4acSJed Brownallexamples = $(examples) $(external_examples)
421686de4acSJed Brown
422686de4acSJed Brown# The test and prove targets can be controlled via pattern searches.  The
423686de4acSJed Brown# default is to run tests and those examples that have no external dependencies.
424686de4acSJed Brown# Examples of finer grained control:
425686de4acSJed Brown#
426686de4acSJed Brown#   make test search='petsc mfem'      # PETSc and MFEM examples
427686de4acSJed Brown#   make prove search='t3'             # t3xx series tests
428686de4acSJed Brown#   make junit search='ex petsc'       # core ex* and PETSc tests
429686de4acSJed Brownsearch ?= t ex
430686de4acSJed Brownrealsearch = $(search:%=%%)
431686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
432686de4acSJed Brown
4332158b1b0Sjeremylt# Test core libCEED
434686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%)
4352158b1b0Sjeremylt
43686a4271fSThilina Rathnayake# Run test target in parallel
4376850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
4383b56482dScamierjs# CPU C tests only for backend %
4393f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
4404859b599SJed Brown
441686de4acSJed Brownprove : BACKENDS += $(TEST_BACKENDS)
44286a4271fSThilina Rathnayakeprove : $(matched)
443a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
444686de4acSJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
44586a4271fSThilina Rathnayake# Run prove target in parallel
4466850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
447bfa078e6SJed Brown
448686de4acSJed Brownprove-all :
449686de4acSJed Brown	+$(MAKE) prove realsearch=%
450686de4acSJed Brown
451686de4acSJed Brownjunit-t% : BACKENDS += $(TEST_BACKENDS)
4528ec9d54bSJed Brownjunit-% : $(OBJDIR)/%
453bdb0bdbbSJed Brown	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
4548ec9d54bSJed Brown
45576174befSjeremyltjunit : $(matched:$(OBJDIR)/%=junit-%)
4568ec9d54bSJed Brown
4572f4d9adbSJeremy L Thompsonall: $(alltests)
4582f4d9adbSJeremy L Thompson
4592f4d9adbSJeremy L Thompsonexamples : $(allexamples)
46086a4271fSThilina Rathnayakeceedexamples : $(examples)
46186a4271fSThilina Rathnayakenekexamples : $(nekexamples)
46286a4271fSThilina Rathnayakemfemexamples : $(mfemexamples)
46386a4271fSThilina Rathnayakepetscexamples : $(petscexamples)
4642f4d9adbSJeremy L Thompson
4652f4d9adbSJeremy L Thompson# Benchmarks
4660c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps
4674e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
4684e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
4694e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
4702f4d9adbSJeremy L Thompson	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
4714e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
4722c6ea02fSJed Brown
4736ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
474d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
475d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
4766ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
4776ea7c6c1SJed Brown	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
4780e439e50SJed Brown
479bf3e26f6SVeselin DobrevOCCA        := $(OCCA_DIR)/bin/occa
480cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl)
481cc6ff0d7SJed Brown
482cc6ff0d7SJed Brownokl-cache :
483cc6ff0d7SJed Brown	$(OCCA) cache ceed $(OKL_KERNELS)
484cc6ff0d7SJed Brown
485cc6ff0d7SJed Brownokl-clear:
486cc6ff0d7SJed Brown	$(OCCA) clear -y -l ceed
487a5ba6ca9Scamierjs
488d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
489bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
490bf3e26f6SVeselin Dobrev	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
4911e25a746SJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
492f91e0974SThilina Rathnayake	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
4931e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
4941e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
495bf3e26f6SVeselin Dobrev	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
496d5217624SJed Brown
497683faae0SJed Brown.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
498d635b4c6Scamierjs
4996e5d1fd9Scamierjscln clean :
500df0ef7e4SVeselin Dobrev	$(RM) -r $(OBJDIR) $(LIBDIR)
50186a4271fSThilina Rathnayake	$(MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
502c4acb06bSStan Tomov	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
503196a75e4SJed Brown	$(RM) benchmarks/*output.txt
5044859b599SJed Brown
50507838a1cSTzaniodistclean : clean
506196a75e4SJed Brown	$(RM) -r doc/html config.mk
50707838a1cSTzanio
5080ab95609SJed Browndoc :
5097bd3a522STzanio	doxygen Doxyfile
5107bd3a522STzanio
511f2fa494dScamierjsstyle :
51220b73d85SJed Brown	@astyle --options=.astylerc \
51320b73d85SJed Brown          $(filter-out include/ceedf.h tests/t310-basis-f.h, \
51420b73d85SJed Brown            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
51520b73d85SJed Brown              examples/*/*.[ch] examples/*/*.[ch]pp))
5160dbfdfc5SJed Brown
517683faae0SJed BrownCLANG_TIDY ?= clang-tidy
518683faae0SJed Brown%.c.tidy : %.c
519683faae0SJed Brown	$(CLANG_TIDY) $^ -- $(CPPFLAGS)
520683faae0SJed Brown
521683faae0SJed Browntidy : $(libceed.c:%=%.tidy)
522683faae0SJed Brown
5234859b599SJed Brownprint :
5244859b599SJed Brown	@echo $(VAR)=$($(VAR))
525582447c9SJed Brown
5269df38c42SVeselin Dobrevprint-% :
5279df38c42SVeselin Dobrev	$(info [ variable name]: $*)
5289df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
5299df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
5309df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
5319df38c42SVeselin Dobrev	$(info )
5329df38c42SVeselin Dobrev	@true
5339df38c42SVeselin Dobrev
534d3c6b40fSJed Brown# "make configure" will autodetect any variables not passed on the
535d3c6b40fSJed Brown# command line, caching the result in config.mk to be used on any
536d3c6b40fSJed Brown# subsequent invocations of make.  For example,
537d3c6b40fSJed Brown#
538d3c6b40fSJed Brown#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
539d3c6b40fSJed Brown#   make
540d3c6b40fSJed Brown#   make prove
541d3c6b40fSJed Brownconfigure :
54257213447SValeria Barra	@: > config.mk
54357213447SValeria Barra	@echo "CC = $(CC)" | tee -a config.mk
54457213447SValeria Barra	@echo "FC = $(FC)" | tee -a config.mk
54557213447SValeria Barra	@echo "NVCC = $(NVCC)" | tee -a config.mk
546d3c6b40fSJed Brown	@echo "CFLAGS = $(CFLAGS)" | tee -a config.mk
547d3c6b40fSJed Brown	@echo "CPPFLAGS = $(CPPFLAGS)" | tee -a config.mk
548d3c6b40fSJed Brown	@echo "FFLAGS = $(FFLAGS)" | tee -a config.mk
549d3c6b40fSJed Brown	@echo "LDFLAGS = $(LDFLAGS)" | tee -a config.mk
550d3c6b40fSJed Brown	@echo "LDLIBS = $(LDLIBS)" | tee -a config.mk
551d3c6b40fSJed Brown	@echo "MAGMA_DIR = $(MAGMA_DIR)" | tee -a config.mk
552d3c6b40fSJed Brown	@echo "XSMM_DIR = $(XSMM_DIR)" | tee -a config.mk
553d3c6b40fSJed Brown	@echo "CUDA_DIR = $(CUDA_DIR)" | tee -a config.mk
554d3c6b40fSJed Brown	@echo "MFEM_DIR = $(MFEM_DIR)" | tee -a config.mk
555d3c6b40fSJed Brown	@echo "PETSC_DIR = $(PETSC_DIR)" | tee -a config.mk
556d3c6b40fSJed Brown	@echo "NEK5K_DIR = $(NEK5K_DIR)" | tee -a config.mk
557d3c6b40fSJed Brown	@echo "Configuration cached in config.mk"
558d3c6b40fSJed Brown
559d3c6b40fSJed Brown.PHONY : configure
560d3c6b40fSJed Brown
561d1f7f8d3SJed Brown-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)
562