1*0006be33SJames WrightCONFIG ?= config.mk 2066464baSJames Wright-include $(CONFIG) 3*0006be33SJames WrightCOMMON ?= common.mk 44f863122SJeremy L Thompson-include $(COMMON) 54f863122SJeremy L Thompson 6*0006be33SJames Wrightpkgconf-path = $(if $(wildcard $(1)/$(2).pc),$(1)/$(2).pc,$(2)) 7ea10196cSJeremy L Thompson 8*0006be33SJames Wright# Library dependencies 9*0006be33SJames Wright# Note: PETSC_ARCH can be undefined or empty for installations which do not use 10*0006be33SJames Wright# PETSC_ARCH - for example when using PETSc installed through Spack. 11*0006be33SJames Wrightifneq ($(wildcard ../petsc/lib/libpetsc.*),) 12*0006be33SJames Wright PETSC_DIR ?= ../petsc 13*0006be33SJames Wrightendif 14*0006be33SJames Wrightpetsc.pc := $(call pkgconf-path,$(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig,petsc) 15*0006be33SJames Wright 16*0006be33SJames WrightCEED_DIR ?= $(if $(wildcard $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/ceed.pc),$(PETSC_DIR)/$(PETSC_ARCH),../libCEED) 17*0006be33SJames Wrightceed.pc := $(call pkgconf-path,$(CEED_DIR)/lib/pkgconfig,ceed) 18*0006be33SJames Wright 19*0006be33SJames Wrightpkgconf = $(shell pkg-config $(if $(STATIC),--static) $1 | sed -e 's/^"//g' -e 's/"$$//g') 20*0006be33SJames Wright 21*0006be33SJames Wright# Error checking flags 22*0006be33SJames WrightPEDANTIC ?= 23*0006be33SJames WrightPEDANTICFLAGS ?= -Werror -pedantic 24*0006be33SJames Wright 25*0006be33SJames WrightCC = $(call pkgconf, --variable=ccompiler $(petsc.pc) $(ceed.pc)) 26a515125bSLeila GhaffariCFLAGS = -std=c99 \ 27*0006be33SJames Wright $(call pkgconf, --variable=cflags_extra $(petsc.pc)) \ 28*0006be33SJames Wright $(call pkgconf, --cflags-only-other $(petsc.pc)) \ 29*0006be33SJames Wright $(OPT) 30*0006be33SJames WrightCPPFLAGS = $(call pkgconf, --cflags-only-I $(petsc.pc) $(ceed.pc)) \ 31*0006be33SJames Wright $(call pkgconf, --variable=cflags_dep $(petsc.pc)) 32*0006be33SJames WrightCXX = $(call pkgconf, --variable=cxxcompiler $(petsc.pc) $(ceed.pc)) 334c07ec22SJames WrightCXXFLAGS = -std=c++17 -Wno-deprecated -Wno-tautological-compare 34*0006be33SJames WrightLDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(petsc.pc) $(ceed.pc)) 35*0006be33SJames WrightLDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(petsc.pc))%, $(call pkgconf, --libs-only-L $(petsc.pc) $(ceed.pc))) 36*0006be33SJames WrightLDLIBS = $(call pkgconf, --libs-only-l $(petsc.pc) $(ceed.pc)) -lm -lstdc++ 37ea10196cSJeremy L Thompson 384c07ec22SJames Wright# ASAN must be left empty if you don't want to use it 394c07ec22SJames WrightASAN ?= 40*0006be33SJames Wright 414c07ec22SJames WrightAFLAGS ?= -fsanitize=address 427df379d9SJames WrightCFLAGS += $(if $(ASAN),$(AFLAGS)) 437df379d9SJames WrightFFLAGS += $(if $(ASAN),$(AFLAGS)) 447df379d9SJames WrightLDFLAGS += $(if $(ASAN),$(AFLAGS)) 45*0006be33SJames Wright 4645101827SJames WrightCPPFLAGS += -I./include 477df379d9SJames Wright 484c07ec22SJames Wright# LibTorch 494c07ec22SJames WrightUSE_TORCH ?= 504c07ec22SJames Wrightifeq ($(USE_TORCH),1) 514c07ec22SJames Wright libtorch.pc := $(shell python ./pytorch_pkgconfig.py) 524c07ec22SJames Wright CPPFLAGS += $(call pkgconf, --cflags-only-I $(libtorch.pc)) 534c07ec22SJames Wright CXXFLAGS += $(call pkgconf, --cflags-only-other $(libtorch.pc)) 544c07ec22SJames Wright LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(libtorch.pc)) 55*0006be33SJames Wright LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(petsc.pc))%, $(call pkgconf, --libs-only-L $(libtorch.pc))) 564c07ec22SJames Wright LDLIBS += $(call pkgconf, --libs-only-l $(libtorch.pc)) 574c07ec22SJames Wright 584c07ec22SJames Wright src.cpp += $(sort $(wildcard $(PROBLEMDIR)/torch/*.cpp)) 594c07ec22SJames Wright src.c += $(sort $(wildcard $(PROBLEMDIR)/torch/*.c)) 604c07ec22SJames Wright 614c07ec22SJames Wright # Intel Pytorch EXtension (IPEX) 624c07ec22SJames Wright IPEX_DIR ?= 634c07ec22SJames Wright ifdef IPEX_DIR 644c07ec22SJames Wright LDFLAGS += -L$(IPEX_DIR)/lib/ 654c07ec22SJames Wright LDFLAGS += -Wl,-rpath,$(IPEX_DIR)/lib/ 664c07ec22SJames Wright LDLIBS += -lintel-ext-pt-gpu 674c07ec22SJames Wright endif 684c07ec22SJames Wrightendif 694c07ec22SJames Wright 704c07ec22SJames Wright# Source Files 71a515125bSLeila GhaffariOBJDIR := build 72a515125bSLeila GhaffariSRCDIR := src 73a515125bSLeila GhaffariPROBLEMDIR := problems 74ea10196cSJeremy L Thompson 75a515125bSLeila Ghaffarisrc.c := navierstokes.c $(sort $(wildcard $(PROBLEMDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/*.c)) 764c07ec22SJames Wrightsrc.o = $(src.c:%.c=$(OBJDIR)/%.o) $(src.cpp:%.cpp=$(OBJDIR)/%.o) 77a515125bSLeila Ghaffari 789e6f9b5eSJames Wright# Path to install directory for SmartRedis. Example: /software/smartredis/install 799e6f9b5eSJames WrightSMARTREDIS_DIR ?= 809e6f9b5eSJames Wrightifdef SMARTREDIS_DIR 819e6f9b5eSJames Wright hiredis.pc := $(SMARTREDIS_DIR)/lib/pkgconfig/hiredis.pc 829e6f9b5eSJames Wright lsmartredis:= -lsmartredis 839e6f9b5eSJames Wright redis++.pc = $(wildcard $(SMARTREDIS_DIR)/lib/pkgconfig/redis++.pc $(SMARTREDIS_DIR)/lib64/pkgconfig/redis++.pc) 849e6f9b5eSJames Wright 859e6f9b5eSJames Wright CPPFLAGS += $(call pkgconf, --cflags-only-I $(hiredis.pc) $(redis++.pc)) 869e6f9b5eSJames Wright LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(hiredis.pc) $(redis++.pc)) 87*0006be33SJames Wright LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(petsc.pc))%, $(call pkgconf, --libs-only-L $(hiredis.pc) $(redis++.pc))) 889e6f9b5eSJames Wright LDLIBS += $(call pkgconf, --libs-only-l $(hiredis.pc) $(redis++.pc)) $(lsmartredis) 899e6f9b5eSJames Wright src.c += $(sort $(wildcard $(SRCDIR)/smartsim/*.c)) 909e6f9b5eSJames Wrightendif 919e6f9b5eSJames Wright 92a515125bSLeila Ghaffariall: navierstokes 93a515125bSLeila Ghaffari 94*0006be33SJames Wright$(OBJDIR)/navierstokes: $(src.o) | navierstokes 95*0006be33SJames Wrightnavierstokes: $(src.o) | $(petsc.pc) $(ceed.pc) 96*0006be33SJames Wright $(call quiet,LINK.o) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $(OBJDIR)/$@ 97a515125bSLeila Ghaffari 98a515125bSLeila Ghaffari.SECONDEXPANSION: # to expand $$(@D)/.DIR 99a515125bSLeila Ghaffari%/.DIR : 100a515125bSLeila Ghaffari @mkdir -p $(@D) 101a515125bSLeila Ghaffari @touch $@ 102ea10196cSJeremy L Thompson 1034f863122SJeremy L Thompson# Quiet, color output 1044f863122SJeremy L Thompsonquiet ?= $($(1)) 1054f863122SJeremy L Thompson 106b92b660dSJames Wright$(OBJDIR)/%.o : %.c Makefile | $$(@D)/.DIR 107a515125bSLeila Ghaffari $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 108a515125bSLeila Ghaffari 109b92b660dSJames Wright$(OBJDIR)/%.o : %.cpp Makefile | $$(@D)/.DIR 1104c07ec22SJames Wright $(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<) 1114c07ec22SJames Wright 112*0006be33SJames Wrightprint: $(petsc.pc) $(ceed.pc) 113ea10196cSJeremy L Thompson $(info CC : $(CC)) 114ea10196cSJeremy L Thompson $(info CFLAGS : $(CFLAGS)) 115ea10196cSJeremy L Thompson $(info CPPFLAGS: $(CPPFLAGS)) 116ea10196cSJeremy L Thompson $(info LDFLAGS : $(LDFLAGS)) 117ea10196cSJeremy L Thompson $(info LDLIBS : $(LDLIBS)) 118ea10196cSJeremy L Thompson $(info OPT : $(OPT)) 119ea10196cSJeremy L Thompson @true 120ea10196cSJeremy L Thompson 1210e8fe9d5SJames Wrightprint-% : 1220e8fe9d5SJames Wright $(info [ variable name]: $*) 1230e8fe9d5SJames Wright $(info [ origin]: $(origin $*)) 1240e8fe9d5SJames Wright $(info [ flavor]: $(flavor $*)) 1250e8fe9d5SJames Wright $(info [ value]: $(value $*)) 1260e8fe9d5SJames Wright $(info [expanded value]: $($*)) 1270e8fe9d5SJames Wright $(info ) 1280e8fe9d5SJames Wright @true 1290e8fe9d5SJames Wright 130ea10196cSJeremy L Thompsonclean: 131a515125bSLeila Ghaffari $(RM) -r $(OBJDIR) navierstokes *.vtu *.bin* *.csv *.png 132ea10196cSJeremy L Thompson 133*0006be33SJames Wright$(petsc.pc): 134ea10196cSJeremy L Thompson $(if $(wildcard $@),,$(error \ 135ea10196cSJeremy L Thompson PETSc config not found. Please set PETSC_DIR and PETSC_ARCH)) 136ea10196cSJeremy L Thompson 137ea10196cSJeremy L Thompson.PHONY: all print clean 138ea10196cSJeremy L Thompson 139*0006be33SJames Wright# Fluid Dynamics Examples 140*0006be33SJames Wrightfluidsexamples.c := $(sort $(wildcard *.c)) 141*0006be33SJames Wrightfluidsexamples.py := smartsim_regression_framework.py 142*0006be33SJames Wrightfluidsexamples := $(fluidsexamples.c:%.c=$(OBJDIR)/%) 143*0006be33SJames Wrightfluidsexamples += $(fluidsexamples.py:%.py=$(OBJDIR)/%) 144*0006be33SJames Wright 145*0006be33SJames Wright$(OBJDIR)/$(fluidsexamples.py): $(OBJDIR)/navierstokes 146*0006be33SJames Wright 147*0006be33SJames Wrightexamples := $(fluidsexamples) 148*0006be33SJames Wright 149*0006be33SJames Wright$(examples) : $(libceed) 150*0006be33SJames Wright$(tests) : $(libceed) 151*0006be33SJames Wright 152*0006be33SJames Wright# Testing 153*0006be33SJames Wrightifeq ($(COVERAGE), 1) 154*0006be33SJames Wright CFLAGS += --coverage 155*0006be33SJames Wright LDFLAGS += --coverage 156*0006be33SJames Wrightendif 157*0006be33SJames Wright 158*0006be33SJames WrightPROVE ?= prove 159*0006be33SJames WrightPROVE_OPTS ?= -j $(NPROCS) 160*0006be33SJames Wright 161*0006be33SJames Wright# Set libCEED backends for testing 162*0006be33SJames WrightCEED_BACKENDS ?= /cpu/self 163*0006be33SJames Wrightexport CEED_BACKENDS 164*0006be33SJames Wright 165*0006be33SJames Wright# Set number processes for testing 166*0006be33SJames WrightNPROC_TEST ?= 1 167*0006be33SJames Wrightexport NPROC_TEST 168*0006be33SJames Wright 169*0006be33SJames Wright# Set pool size for testing 170*0006be33SJames WrightNPROC_POOL ?= 1 171*0006be33SJames Wrightexport NPROC_POOL 172*0006be33SJames Wright 173*0006be33SJames WrightJUNIT_BATCH ?= '' 174*0006be33SJames Wright 175*0006be33SJames Wrightrun-% : $(OBJDIR)/% 176*0006be33SJames Wright @$(PYTHON) tests/junit.py --ceed-backends $(CEED_BACKENDS) --mode tap $(if $(SMARTREDIS_DIR),--smartredis_dir $(SMARTREDIS_DIR) ) $(if $(USE_TORCH),--has_torch $(USE_TORCH) )--nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) $(<:$(OBJDIR)/%=%) 177*0006be33SJames Wright 178*0006be33SJames Wright# The test and prove targets can be controlled via pattern searches. The default 179*0006be33SJames Wright# is to run all tests and examples. Examples of finer grained control: 180*0006be33SJames Wright# 181*0006be33SJames Wright# make prove search='t3' # t3xx series tests 182*0006be33SJames Wright# make junit search='t ex' # core tests and examples 183*0006be33SJames Wrightsearch ?= navierstokes 184*0006be33SJames Wrightrealsearch = $(search:%=%%) 185*0006be33SJames Wrightmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(examples))) 186*0006be33SJames Wright 187*0006be33SJames Wright# Test 188*0006be33SJames Wrighttest : $(matched:$(OBJDIR)/%=run-%) 189*0006be33SJames Wright 190*0006be33SJames Wrighttst : ;@$(MAKE) $(MFLAGS) V=$(V) test 191*0006be33SJames Wright 192*0006be33SJames Wright# Test with TAP output 193*0006be33SJames Wrightprove : $(matched) 194*0006be33SJames Wright $(info Running unit tests) 195*0006be33SJames Wright $(info - Testing with libCEED backends: $(CEED_BACKENDS)) 196*0006be33SJames Wright $(info - Testing on $(NPROC_TEST) processes) 197*0006be33SJames Wright $(PROVE) $(PROVE_OPTS) --exec '$(PYTHON) tests/junit.py --petsc-arch $(or $(PETSC_ARCH),$(PETSC_DIR)) --ceed-backends $(CEED_BACKENDS) --mode tap $(if $(SMARTREDIS_DIR),--smartredis_dir $(SMARTREDIS_DIR) ) $(if $(USE_TORCH),--has_torch $(USE_TORCH) )--nproc $(NPROC_TEST) --pool-size $(NPROC_POOL)' $(matched:$(OBJDIR)/%=%) 198*0006be33SJames Wright 199*0006be33SJames Wrightprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 200*0006be33SJames Wright 201*0006be33SJames Wrightprove-all : 202*0006be33SJames Wright +$(MAKE) prove realsearch=% 203*0006be33SJames Wright 204*0006be33SJames Wright# Test with JUNIT output 205*0006be33SJames Wrightjunit-% : $(OBJDIR)/% 206*0006be33SJames Wright @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py --junit-batch $(JUNIT_BATCH) --petsc-arch $(or $(PETSC_ARCH),$(PETSC_DIR)) --ceed-backends $(CEED_BACKENDS) $(if $(SMARTREDIS_DIR),--smartredis_dir $(SMARTREDIS_DIR) ) $(if $(USE_TORCH),--has_torch $(USE_TORCH) )--nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) $(<:$(OBJDIR)/%=%) 207*0006be33SJames Wright 208*0006be33SJames Wrightjunit : $(matched:$(OBJDIR)/%=junit-%) 209*0006be33SJames Wright 210*0006be33SJames Wright 211*0006be33SJames Wright# Configure 212*0006be33SJames Wright# "make configure" detects any variables passed on the command line or 213*0006be33SJames Wright# previously set in config.mk, caching them in config.mk as simple 214*0006be33SJames Wright# (:=) variables. Variables set in config.mk or on the command line 215*0006be33SJames Wright# take precedence over the defaults provided in the file. Typical 216*0006be33SJames Wright# usage: 217*0006be33SJames Wright# 218*0006be33SJames Wright# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 219*0006be33SJames Wright# make 220*0006be33SJames Wright# make prove 221*0006be33SJames Wright# 222*0006be33SJames Wright# The values in the file can be updated by passing them on the command 223*0006be33SJames Wright# line, e.g., 224*0006be33SJames Wright# 225*0006be33SJames Wright# make configure CC=/path/to/other/clang 226*0006be33SJames Wright 227*0006be33SJames Wright# All variables to consider for caching 228*0006be33SJames WrightCONFIG_VARS = CEED_DIR PETSC_DIR PETSC_ARCH CCOPT CFLAGS CPPFLAGS AR ARFLAGS LDFLAGS LDLIBS SED USE_TORCH SMARTREDIS_DIR 229*0006be33SJames Wright 230*0006be33SJames Wright# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS 231*0006be33SJames Wright# was set on the command line or in config.mk (where it will appear as 232*0006be33SJames Wright# a simple variable). 233*0006be33SJames Wrightneeds_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1)))) 234*0006be33SJames Wright 235*0006be33SJames Wrightconfigure : 236*0006be33SJames Wright $(file > $(CONFIG)) 237*0006be33SJames Wright $(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v))))) 238*0006be33SJames Wright @echo "Configuration cached in $(CONFIG):" 239*0006be33SJames Wright @cat $(CONFIG) 240a515125bSLeila Ghaffari 241a515125bSLeila Ghaffari-include $(src.o:%.o=%.d) 242