xref: /honee/Makefile (revision 9b103f75867128bb395d4431a2dd4da8eacd1da9)
1# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3# 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
17CONFIG ?= ../../config.mk
18-include $(CONFIG)
19COMMON ?= ../../common.mk
20-include $(COMMON)
21
22PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc
23CEED_DIR ?= ../..
24ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
25
26CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
27CFLAGS = -std=c99 \
28  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
29  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
30  $(OPT) $(OPT_EXAMPLES)
31CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
32  $(call pkgconf, --variable=cflags_dep $(PETSc.pc))
33CXX = $(call pkgconf, --variable=cxxcompiler $(PETSc.pc) $(ceed.pc))
34CXXFLAGS = -std=c++17 -Wno-deprecated -Wno-tautological-compare
35LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
36LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
37LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm -lstdc++
38
39# Address Sanitizer Setup
40# ASAN must be left empty if you don't want to use it
41ASAN ?=
42AFLAGS ?= -fsanitize=address
43# Also: -fsanitize=undefined -fno-omit-frame-pointer
44CFLAGS += $(if $(ASAN),$(AFLAGS))
45FFLAGS += $(if $(ASAN),$(AFLAGS))
46LDFLAGS += $(if $(ASAN),$(AFLAGS))
47CPPFLAGS += -I./include
48
49# LibTorch
50USE_TORCH ?=
51ifeq ($(USE_TORCH),1)
52  libtorch.pc := $(shell python ./pytorch_pkgconfig.py)
53  CPPFLAGS += $(call pkgconf, --cflags-only-I $(libtorch.pc))
54  CXXFLAGS += $(call pkgconf, --cflags-only-other $(libtorch.pc))
55  LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(libtorch.pc))
56  LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(libtorch.pc)))
57  LDLIBS += $(call pkgconf, --libs-only-l $(libtorch.pc))
58
59  src.cpp += $(sort $(wildcard $(PROBLEMDIR)/torch/*.cpp))
60  src.c += $(sort $(wildcard $(PROBLEMDIR)/torch/*.c))
61
62  # Intel Pytorch EXtension (IPEX)
63  IPEX_DIR ?=
64  ifdef IPEX_DIR
65      LDFLAGS += -L$(IPEX_DIR)/lib/
66      LDFLAGS += -Wl,-rpath,$(IPEX_DIR)/lib/
67      LDLIBS += -lintel-ext-pt-gpu
68  endif
69endif
70
71# Source Files
72OBJDIR := build
73SRCDIR := src
74PROBLEMDIR := problems
75
76src.c := navierstokes.c $(sort $(wildcard $(PROBLEMDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/*.c))
77src.o = $(src.c:%.c=$(OBJDIR)/%.o) $(src.cpp:%.cpp=$(OBJDIR)/%.o)
78
79# Path to install directory for SmartRedis. Example: /software/smartredis/install
80SMARTREDIS_DIR ?=
81ifdef SMARTREDIS_DIR
82	hiredis.pc := $(SMARTREDIS_DIR)/lib/pkgconfig/hiredis.pc
83	lsmartredis:= -lsmartredis
84	redis++.pc = $(wildcard $(SMARTREDIS_DIR)/lib/pkgconfig/redis++.pc $(SMARTREDIS_DIR)/lib64/pkgconfig/redis++.pc)
85
86	CPPFLAGS += $(call pkgconf, --cflags-only-I $(hiredis.pc) $(redis++.pc))
87	LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(hiredis.pc) $(redis++.pc))
88	LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(hiredis.pc) $(redis++.pc)))
89	LDLIBS += $(call pkgconf, --libs-only-l $(hiredis.pc) $(redis++.pc)) $(lsmartredis)
90	src.c += $(sort $(wildcard $(SRCDIR)/smartsim/*.c))
91endif
92
93all: navierstokes
94
95navierstokes: $(src.o) | $(PETSc.pc) $(ceed.pc)
96	$(call quiet,LINK.o) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
97
98.SECONDEXPANSION: # to expand $$(@D)/.DIR
99%/.DIR :
100	@mkdir -p $(@D)
101	@touch $@
102
103# Quiet, color output
104quiet ?= $($(1))
105
106$(OBJDIR)/%.o : %.c  Makefile | $$(@D)/.DIR
107	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
108
109$(OBJDIR)/%.o : %.cpp Makefile | $$(@D)/.DIR
110	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
111
112print: $(PETSc.pc) $(ceed.pc)
113	$(info CC      : $(CC))
114	$(info CFLAGS  : $(CFLAGS))
115	$(info CPPFLAGS: $(CPPFLAGS))
116	$(info LDFLAGS : $(LDFLAGS))
117	$(info LDLIBS  : $(LDLIBS))
118	$(info OPT     : $(OPT))
119	@true
120
121print-% :
122	$(info [ variable name]: $*)
123	$(info [        origin]: $(origin $*))
124	$(info [        flavor]: $(flavor $*))
125	$(info [         value]: $(value $*))
126	$(info [expanded value]: $($*))
127	$(info )
128	@true
129
130clean:
131	$(RM) -r $(OBJDIR) navierstokes *.vtu *.bin* *.csv *.png
132
133$(PETSc.pc):
134	$(if $(wildcard $@),,$(error \
135	  PETSc config not found. Please set PETSC_DIR and PETSC_ARCH))
136
137.PHONY: all print clean
138
139pkgconf = $(shell pkg-config $(if $(STATIC),--static) $1 | sed -e 's/^"//g' -e 's/"$$//g')
140
141-include $(src.o:%.o=%.d)
142