xref: /libCEED/examples/fluids/Makefile (revision 013a555157cefb861605c4e4ea6ce4e03bb7c3d7)
1ccaff030SJeremy L Thompson# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2ccaff030SJeremy L Thompson# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3ccaff030SJeremy L Thompson# reserved. See files LICENSE and NOTICE for details.
4ccaff030SJeremy L Thompson#
5ccaff030SJeremy L Thompson# This file is part of CEED, a collection of benchmarks, miniapps, software
6ccaff030SJeremy L Thompson# libraries and APIs for efficient high-order finite element and spectral
7ccaff030SJeremy L Thompson# element discretizations for exascale applications. For more information and
83d8e8822SJeremy L Thompson# source code availability see http://github.com/ceed
9ccaff030SJeremy L Thompson#
10ccaff030SJeremy L Thompson# The CEED research is supported by the Exascale Computing Project (17-SC-20-SC)
11ccaff030SJeremy L Thompson# a collaborative effort of two U.S. Department of Energy organizations (Office
12ccaff030SJeremy L Thompson# of Science and the National Nuclear Security Administration) responsible for
13ccaff030SJeremy L Thompson# the planning and preparation of a capable exascale ecosystem, including
14ccaff030SJeremy L Thompson# software, applications, hardware, advanced system engineering and early
15ccaff030SJeremy L Thompson# testbed platforms, in support of the nation's exascale computing imperative.
16ccaff030SJeremy L Thompson
17e51ac267SJames WrightCONFIG ?= ../../config.mk
18e51ac267SJames Wright-include $(CONFIG)
19777ff853SJeremy L ThompsonCOMMON ?= ../../common.mk
20777ff853SJeremy L Thompson-include $(COMMON)
21777ff853SJeremy L Thompson
22ccaff030SJeremy L ThompsonPETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc
23ccaff030SJeremy L ThompsonCEED_DIR ?= ../..
24ccaff030SJeremy L Thompsonceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
25ccaff030SJeremy L Thompson
26ccaff030SJeremy L ThompsonCC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
2777841947SLeila GhaffariCFLAGS = -std=c99 \
2877841947SLeila Ghaffari  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
2977841947SLeila Ghaffari  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
30e334ad8fSJed Brown  $(OPT) $(OPT_EXAMPLES)
3177841947SLeila GhaffariCPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
3277841947SLeila Ghaffari  $(call pkgconf, --variable=cflags_dep $(PETSc.pc))
33*013a5551SJames WrightCXX = $(call pkgconf, --variable=cxxcompiler $(PETSc.pc) $(ceed.pc))
34*013a5551SJames WrightCXXFLAGS = -std=c++17 -Wno-deprecated -Wno-tautological-compare
35ccaff030SJeremy L ThompsonLDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
36ccaff030SJeremy L ThompsonLDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
37*013a5551SJames WrightLDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm -lstdc++
38ccaff030SJeremy L Thompson
39*013a5551SJames Wright# Address Sanitizer Setup
40*013a5551SJames Wright# ASAN must be left empty if you don't want to use it
41*013a5551SJames WrightASAN ?=
42*013a5551SJames WrightAFLAGS ?= -fsanitize=address
43*013a5551SJames Wright# Also: -fsanitize=undefined -fno-omit-frame-pointer
441b561cd6SJames WrightCFLAGS += $(if $(ASAN),$(AFLAGS))
451b561cd6SJames WrightFFLAGS += $(if $(ASAN),$(AFLAGS))
461b561cd6SJames WrightLDFLAGS += $(if $(ASAN),$(AFLAGS))
47ed9ed3deSJames WrightCPPFLAGS += -I./include
481b561cd6SJames Wright
49*013a5551SJames Wright# LibTorch
50*013a5551SJames WrightUSE_TORCH ?=
51*013a5551SJames Wrightifeq ($(USE_TORCH),1)
52*013a5551SJames Wright  libtorch.pc := $(shell python ./pytorch_pkgconfig.py)
53*013a5551SJames Wright  CPPFLAGS += $(call pkgconf, --cflags-only-I $(libtorch.pc))
54*013a5551SJames Wright  CXXFLAGS += $(call pkgconf, --cflags-only-other $(libtorch.pc))
55*013a5551SJames Wright  LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(libtorch.pc))
56*013a5551SJames Wright  LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(libtorch.pc)))
57*013a5551SJames Wright  LDLIBS += $(call pkgconf, --libs-only-l $(libtorch.pc))
58*013a5551SJames Wright
59*013a5551SJames Wright  src.cpp += $(sort $(wildcard $(PROBLEMDIR)/torch/*.cpp))
60*013a5551SJames Wright  src.c += $(sort $(wildcard $(PROBLEMDIR)/torch/*.c))
61*013a5551SJames Wright
62*013a5551SJames Wright  # Intel Pytorch EXtension (IPEX)
63*013a5551SJames Wright  IPEX_DIR ?=
64*013a5551SJames Wright  ifdef IPEX_DIR
65*013a5551SJames Wright      LDFLAGS += -L$(IPEX_DIR)/lib/
66*013a5551SJames Wright      LDFLAGS += -Wl,-rpath,$(IPEX_DIR)/lib/
67*013a5551SJames Wright      LDLIBS += -lintel-ext-pt-gpu
68*013a5551SJames Wright  endif
69*013a5551SJames Wrightendif
70*013a5551SJames Wright
71*013a5551SJames Wright# Source Files
7277841947SLeila GhaffariOBJDIR := build
7377841947SLeila GhaffariSRCDIR := src
7477841947SLeila GhaffariPROBLEMDIR := problems
75ccaff030SJeremy L Thompson
7677841947SLeila Ghaffarisrc.c := navierstokes.c $(sort $(wildcard $(PROBLEMDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/*.c))
77*013a5551SJames Wrightsrc.o = $(src.c:%.c=$(OBJDIR)/%.o) $(src.cpp:%.cpp=$(OBJDIR)/%.o)
7877841947SLeila Ghaffari
79fc818f1bSJames Wright# Path to install directory for SmartRedis. Example: /software/smartredis/install
80fc818f1bSJames WrightSMARTREDIS_DIR ?=
81fc818f1bSJames Wrightifdef SMARTREDIS_DIR
82fc818f1bSJames Wright	hiredis.pc := $(SMARTREDIS_DIR)/lib/pkgconfig/hiredis.pc
83fc818f1bSJames Wright	lsmartredis:= -lsmartredis
84fc818f1bSJames Wright	redis++.pc = $(wildcard $(SMARTREDIS_DIR)/lib/pkgconfig/redis++.pc $(SMARTREDIS_DIR)/lib64/pkgconfig/redis++.pc)
85fc818f1bSJames Wright
86fc818f1bSJames Wright	CPPFLAGS += $(call pkgconf, --cflags-only-I $(hiredis.pc) $(redis++.pc))
87fc818f1bSJames Wright	LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(hiredis.pc) $(redis++.pc))
88fc818f1bSJames Wright	LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(hiredis.pc) $(redis++.pc)))
89fc818f1bSJames Wright	LDLIBS += $(call pkgconf, --libs-only-l $(hiredis.pc) $(redis++.pc)) $(lsmartredis)
90fc818f1bSJames Wright	src.c += $(sort $(wildcard $(SRCDIR)/smartsim/*.c))
91fc818f1bSJames Wrightendif
92fc818f1bSJames Wright
9377841947SLeila Ghaffariall: navierstokes
9477841947SLeila Ghaffari
9577841947SLeila Ghaffarinavierstokes: $(src.o) | $(PETSc.pc) $(ceed.pc)
96*013a5551SJames Wright	$(call quiet,LINK.o) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
9777841947SLeila Ghaffari
9877841947SLeila Ghaffari.SECONDEXPANSION: # to expand $$(@D)/.DIR
9977841947SLeila Ghaffari%/.DIR :
10077841947SLeila Ghaffari	@mkdir -p $(@D)
10177841947SLeila Ghaffari	@touch $@
102ccaff030SJeremy L Thompson
103777ff853SJeremy L Thompson# Quiet, color output
104777ff853SJeremy L Thompsonquiet ?= $($(1))
105777ff853SJeremy L Thompson
10677841947SLeila Ghaffari$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
10777841947SLeila Ghaffari	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
10877841947SLeila Ghaffari
109*013a5551SJames Wright$(OBJDIR)/%.o : %.cpp | $$(@D)/.DIR
110*013a5551SJames Wright	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
111*013a5551SJames Wright
112ccaff030SJeremy L Thompsonprint: $(PETSc.pc) $(ceed.pc)
113ccaff030SJeremy L Thompson	$(info CC      : $(CC))
114ccaff030SJeremy L Thompson	$(info CFLAGS  : $(CFLAGS))
115ccaff030SJeremy L Thompson	$(info CPPFLAGS: $(CPPFLAGS))
116ccaff030SJeremy L Thompson	$(info LDFLAGS : $(LDFLAGS))
117ccaff030SJeremy L Thompson	$(info LDLIBS  : $(LDLIBS))
118ccaff030SJeremy L Thompson	$(info OPT     : $(OPT))
119ccaff030SJeremy L Thompson	@true
120ccaff030SJeremy L Thompson
121a25bd800SJames Wrightprint-% :
122a25bd800SJames Wright	$(info [ variable name]: $*)
123a25bd800SJames Wright	$(info [        origin]: $(origin $*))
124a25bd800SJames Wright	$(info [        flavor]: $(flavor $*))
125a25bd800SJames Wright	$(info [         value]: $(value $*))
126a25bd800SJames Wright	$(info [expanded value]: $($*))
127a25bd800SJames Wright	$(info )
128a25bd800SJames Wright	@true
129a25bd800SJames Wright
130ccaff030SJeremy L Thompsonclean:
13177841947SLeila Ghaffari	$(RM) -r $(OBJDIR) navierstokes *.vtu *.bin* *.csv *.png
132ccaff030SJeremy L Thompson
133ccaff030SJeremy L Thompson$(PETSc.pc):
134ccaff030SJeremy L Thompson	$(if $(wildcard $@),,$(error \
135ccaff030SJeremy L Thompson	  PETSc config not found. Please set PETSC_DIR and PETSC_ARCH))
136ccaff030SJeremy L Thompson
137ccaff030SJeremy L Thompson.PHONY: all print clean
138ccaff030SJeremy L Thompson
139a25bd800SJames Wrightpkgconf = $(shell pkg-config $(if $(STATIC),--static) $1 | sed -e 's/^"//g' -e 's/"$$//g')
14077841947SLeila Ghaffari
14177841947SLeila Ghaffari-include $(src.o:%.o=%.d)
142