1# -*- mode: makefile-gmake -*- 2# 3# Contains rules for building PETSc application codes (not PETSc libraries). 4# * for example, make ex1 5# * included only in makefiles in directories that can build executables such as /tutorials, /tests, and their subdirectores 6# * requires GNUmake 7# 8# It may be included in users makefiles (with include ${PETSC_DIR}/lib/petsc/conf/rules) 9# The makefile will then compile executables that link against the PETSc libraries 10# See https://petsc.org/release/docs/manual/getting_started/#writing-c-c-or-fortran-applications 11 12.SUFFIXES: .F .F90 .f90 ${SUFFIXES} .PETSc .C .cc .cpp .cxx .r .rm .so .html .ad .m .F95 .f95 .fiat .cu .hip.cxx .kokkos.cxx .raja.cxx .sycl.cxx 13 14clean-legacy: 15 @-${RM} ${CLEANFILES} ${TESTS} *.o *.lo *~ \ 16 ex[0-9] ex[0-9][0-9] ex[0-9][0-9][0-9] \ 17 ex[0-9]f ex[0-9][0-9]f ex[0-9][0-9][0-9]f \ 18 ex[0-9]k ex[0-9][0-9]k ex[0-9][0-9][0-9]k \ 19 ex[0-9]f90 ex[0-9][0-9]f90 ex[0-9][0-9][0-9]f90 \ 20 ex[0-9]cu ex[0-9][0-9]cu ex[0-9][0-9][0-9]cu \ 21 ex[0-9].exe ex[0-9][0-9].exe ex[0-9][0-9][0-9].exe \ 22 ex[0-9]f.exe ex[0-9][0-9]f.exe ex[0-9][0-9][0-9]f.exe \ 23 ex[0-9]f90.exe ex[0-9][0-9]f90.exe ex[0-9][0-9][0-9]f90.exe \ 24 ex[0-9]cu.exe ex[0-9][0-9]cu.exe ex[0-9][0-9][0-9]cu.exe \ 25 ex[0-9]hip ex[0-9][0-9]hip ex[0-9][0-9][0-9]hip \ 26 ex[0-9]hip.exe ex[0-9][0-9]hip.exe ex[0-9][0-9][0-9]hip.exe \ 27 ex[0-9]sycl ex[0-9][0-9]sycl ex[0-9][0-9][0-9]sycl \ 28 ex[0-9]sycl.exe ex[0-9][0-9]sycl.exe ex[0-9][0-9][0-9]sycl.exe \ 29 PI* *.ln l.outa* mputil.mp_* core core.* *.tmp *.map gmon.out *.gcov.html \ 30 trashz \#*\# *.mex* *.stolen *.trace Log.* *.stolen \ 31 output/*~ .mpirtmp mon.out *.aus *.mon.* p4pg ins10*.c \ 32 *.cp_ *.cp__ *.c*.c \ 33 *.dep *.proj ctoatmp PETScArena* *.L *.anl *.mod .mpi* *.d \ 34 *.class *.ouit *.ad.* g_* silly.cmp *.tmp.* *.ilk *.pdb *.inst.c *.rej *.gcda *.gcno 35 @-${RM} -rf ${CLEANDIRS} *.dSYM AD_cache SunWS_cache 36 37clean:: clean-legacy 38 39# 40# These rules are for compiling the test examples. 41# 42.cpp.rm .cxx.rm .cc.rm .C.rm .F.rm .F90.rm .f.rm .c.rm .cu.rm: 43 -@${RM} $* *.o $*.mon.* gmon.out mon.out 44 -@${RM} *.exe *.ilk *.pdb *.tds 45.cu.PETSc .hip.cxx.PETSc .kokkos.cxx.PETSc .c.PETSc .cxx.PETSc: 46 -@if [ "$V" = "1" ]; then echo "** Building $* in $${PWD}"; fi 47 -+@${OMAKE} PETSC_ARCH=${PETSC_ARCH} $* > trashz 2>&1 48 -@grep -v clog trashz | grep -v "information sections" | \ 49 grep -v "warning C4003: not enough actual parameters for macro 'PETSC_PASTE3_" | \ 50 grep -v "(aka 'long \*') doesn't match specified 'MPI' type tag that requires 'long long \*'" | \ 51 grep -v "note: expanded from macro" |\ 52 grep -v "MPI_" | \ 53 grep -v "warnings generated" | \ 54 grep -v "WARNING: TOC" | \ 55 grep -v "D4024 : unrecognized" | \ 56 grep -v "tentative definition of size" | \ 57 grep -v "Extra instructions" | \ 58 grep -v "Unused external reference" | \ 59 grep -v "Warning: attribute unused is unsupported and will be skipped" | \ 60 grep -v "f90 continuing despite warning messages" | \ 61 grep -v "symbol if the" | \ 62 grep -v "ignoring symbol version info" | \ 63 grep -v "warning: initializer element is not computable at load time" | \ 64 grep -v "warning: ISO C90 forbids mixed declarations and code" | \ 65 grep -v "warning: ISO C90 does not support 'static' or type qualifiers in parameter array declarators" | \ 66 grep -v "warning, duplicate dylib" | \ 67 grep -v "warning: duplicate dylib" | \ 68 grep -v "preempts that definition" | \ 69 grep -v "is an array from" | \ 70 grep -v "At least one PA 2.0" | \ 71 grep -v "Cannot cast" | \ 72 grep -v "WARNING 134: weak definition of" | \ 73 grep -v "Warning(s) detected" | \ 74 grep -v "object file assumed" | \ 75 grep -v "consider using mkstemp" |\ 76 grep -v EXTERNAL |\ 77 grep -v "warning prebinding disabled" |\ 78 grep -v volatile |\ 79 grep -v -i inconsistent |\ 80 grep -v Anachronism | \ 81 grep -v "/opt/ibmcmp/xlsmp/1.3/lib" | \ 82 grep -v "add line info to anonymous symbol" | \ 83 grep -v "/opt/ibmcmp/xlsmp/1.3/../.." | \ 84 grep -v "IPO Error: unresolved" | \ 85 grep -v "is being replaced by a real definition" | \ 86 grep -v "may result in errors or" | \ 87 grep -v "is deprecated" | \ 88 grep -v " -Werror" | \ 89 grep -v " was built for newer macOS version " | \ 90 grep -v "duplicate -rpath" | \ 91 grep -v "only the last is used because nvcc can only accept a single optimization setting" | \ 92 grep -E -i '(Error|warning|Can|Unresolved)' >> /dev/null;\ 93 if [ "$$?" != 1 ]; then \ 94 printf ${PETSC_TEXT_HILIGHT}"*******************Error detected during compile or link!*******************\n";\ 95 echo "See https://petsc.org/release/faq/";\ 96 echo ${PWD} $* ;\ 97 printf "*********************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;\ 98 cat trashz ; elif [ "$V" = "1" ]; then cat trashz; fi; ${RM} trashz 99 100.F.PETSc .F90.PETSc: 101 -@if [ "$V" = "1" ]; then echo "** Building $* in $${PWD}"; fi 102 -+@${OMAKE} PETSC_ARCH=${PETSC_ARCH} $* > trashz 2>&1 103 -@grep -v EXTERNAL trashz | grep -v Wall | \ 104 grep -v "warning: In-place macro substitution leaves line truncated" | \ 105 grep -v "Warning: Same actual argument associated with INTENT(IN) argument 'errorcode' and INTENT(OUT) argument 'ierror' at (1)" | \ 106 grep -v "Unused external reference" | \ 107 grep -v "D4024 : unrecognized" | \ 108 grep -v "WARNING: TOC overflow." | \ 109 grep -v "Extra instructions are being" | \ 110 grep -v "tentative definition of size" | \ 111 grep -v "symbol if the symbol" | \ 112 grep -v -i inconsistent | \ 113 grep -v -i "unused dummy" | \ 114 grep -v "alignment lost in merging tentative definition" | \ 115 grep -v "WARNING: -cpp is ignored" | \ 116 grep -v "ignoring symbol version info" | \ 117 grep -v "At least one PA 2.0" | \ 118 grep -v "Inconsistent structure" | \ 119 grep -v "object file assumed" | \ 120 grep -v "ex20.F:30:" | \ 121 grep -v "ex20f.F:31: warning" | \ 122 grep -v "f90 continuing despite warning messages" | \ 123 grep -v "is an array from" | \ 124 grep -v "warning, duplicate dylib" | \ 125 grep -v "warning: duplicate dylib" | \ 126 grep -v "consider using mkstemp" |\ 127 grep -v "Nonconforming tab character" |\ 128 grep -v "Unused external reference" | \ 129 grep -v "WARNING 134: weak definition of" | \ 130 grep -v 'continuing despite warning messages' | \ 131 grep -v "add line info to anonymous symbol" | \ 132 grep -v "warning prebinding disabled" |\ 133 grep -v "ex20f.F:34: warning:" | \ 134 grep -v "Unused dummy argument" | \ 135 grep -v "is being replaced by a real definition" | \ 136 grep -v "IPO Error: unresolved" | \ 137 grep -v "warning multiple definitions of symbol _matdensegetarray_" | \ 138 grep -v " -Werror" | \ 139 grep -v " was built for newer macOS version " | \ 140 grep -v "duplicate -rpath" | \ 141 grep -E -i '(Error|warning|Can|Unresolved)' >> /dev/null ; \ 142 if [ "$$?" != 1 ]; then \ 143 printf ${PETSC_TEXT_HILIGHT}"*******************Error detected during compile or link!*******************\n";\ 144 echo "See https://petsc.org/release/faq/";\ 145 echo ${PWD} $* ;\ 146 printf "*********************************************************"${PETSC_TEXT_NORMAL}"\n" ;\ 147 cat trashz ; elif [ "$V" = "1" ]; then cat trashz; fi; ${RM} trashz 148 149.c.o: 150 ${PETSC_COMPILE_SINGLE} $< 151 152.cpp.o .cxx.o .cc.o .C.o: 153 ${PETSC_CXXCOMPILE_SINGLE} $< 154 155.cu.o: 156 ${PETSC_CUCOMPILE_SINGLE} $< 157 158.hip.cxx.o: 159 ${PETSC_HIPCOMPILE_SINGLE} $< 160 161.kokkos.cxx.o: 162 ${PETSC_KOKKOSCOMPILE_SINGLE} $< 163 164.sycl.cxx.o: 165 ${PETSC_SYCLCOMPILE_SINGLE} $< 166 167.raja.cxx.o: 168 ${PETSC_RAJACOMPILE_SINGLE} $< 169 170.F.o .F90.o .F95.o: 171 ${PETSC_FCOMPILE_SINGLE} $< 172 173.f.o .f90.o .f95.o: 174 ${FC} -c ${FC_FLAGS} ${FFLAGS} -o $@ $< 175 176ifeq ($(RM),true) 177.SECONDARY: $(%.o) $(%f.o) $(%f90.o) 178endif 179 180LINK.c = $(CLINKER) $(CCPPFLAGS) $(LDFLAGS) $(EXEFLAGS) 181LINK.o = $(CLINKER) $(LDFLAGS) $(EXEFLAGS) 182LINK.F = $(FLINKER) $(FCPPFLAGS) $(LDFLAGS) 183LINK.cc = $(CXXLINKER) $(CXXCPPFLAGS) $(LDFLAGS) 184 185# make macros KOKKOS_USE_CUDA_COMPILER etc are defined in `${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables` 186ifneq ($(KOKKOS_USE_CUDA_COMPILER),) 187 # Kokkos requires nvcc to be in PATH and the C++ compiler to be given in an environmental variable 188 # We prefer to use the Kokkos nvcc_wrapper compiler wrapper for compiling Kokkos files. The command is adapted from PETSC_COMPILE.kokkos.cxx 189 # in gmakefile.test, with additional "-o $*.o" to generate intended foo.o instead of foo.kokkos.o 190 KOKKOS_COMPILE_SINGLE = PATH=`dirname $(CUDAC)`:$(PATH) NVCC_WRAPPER_DEFAULT_COMPILER="$(CUDA_CXX)" $(KOKKOS_BIN)/nvcc_wrapper --expt-extended-lambda --expt-relaxed-constexpr -c $(CUDAC_FLAGS) ${PETSC_CCPPFLAGS} $(CUDACPPFLAGS) $(CUDA_CXXFLAGS) $(MPICXX_INCLUDES) -o $*.o 191 KOKKOS_LINK = PATH=`dirname $(CUDAC)`:$(PATH) NVCC_WRAPPER_DEFAULT_COMPILER=$(CUDA_CXX) $(KOKKOS_BIN)/nvcc_wrapper --expt-extended-lambda --expt-relaxed-constexpr $(CUDAC_FLAGS) $(MPICXX_INCLUDES) ${PETSC_CCPPFLAGS} $(CUDA_CXXFLAGS) $(CUDACPPFLAGS) $(CUDA_CXXLIBS) $(MPICXX_LIBS) $(LDFLAGS) 192else ifneq ($(KOKKOS_USE_HIP_COMPILER),) 193 KOKKOS_COMPILE_SINGLE = ${PETSC_HIPCOMPILE_SINGLE} 194 KOKKOS_LINK = $(HIPC) $(HIPC_FLAGS) $(HIPPP_FLAGS) $(HIPOPTFLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(LDFLAGS) $(MPICXX_INCLUDES) $(MPICXX_LIBS) 195else ifneq ($(KOKKOS_USE_SYCL_COMPILER),) 196 KOKKOS_COMPILE_SINGLE = ${PETSC_SYCLCOMPILE_SINGLE} 197 KOKKOS_LINK = $(SYCLC) $(SYCLC_FLAGS) $(SYCLC_LINKER_FLAGS) $(SYCLOPTFLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(SYCLPP_FLAGS) $(LDFLAGS) $(MPICXX_INCLUDES) $(MPICXX_LIBS) 198else 199 KOKKOS_COMPILE_SINGLE = ${PETSC_CXXCOMPILE_SINGLE} 200 KOKKOS_LINK = $(CXXLINKER) $(CXX_FLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(LDFLAGS) $(MPICXX_INCLUDES) $(MPICXX_LIBS) 201endif 202 203# Why do we filter out -fvisibility=hidden? See comments in gmakefile.test on PETSC_COMPILE.kokkos.cxx 204PETSC_KOKKOSCOMPILE_SINGLE = $(filter-out -fvisibility=hidden,$(subst -Xcompiler -fvisibility=hidden ,,$(strip $(KOKKOS_COMPILE_SINGLE)))) 205LINK.kokkos.cxx = $(filter-out -fvisibility=hidden,$(subst -Xcompiler -fvisibility=hidden ,,$(strip $(KOKKOS_LINK)))) 206 207LINK.hip.cxx = $(HIPC) $(HIPC_FLAGS) $(HIPPP_FLAGS) $(HIPOPTFLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(LDFLAGS) $(MPICXX_INCLUDES) $(MPICXX_LIBS) 208 209ifneq ($(RAJA_USE_CUDA_COMPILER),) 210 PETSC_RAJACOMPILE_SINGLE = ${CUDAC} -o $*.o $(MPICXX_INCLUDES) ${CUDAC_FLAGS} -x cu -Xcudafe "--display_error_number" -c --compiler-options="${PETSC_CCPPFLAGS} ${PETSC_CC_INCLUDES} ${CUDA_CXXFLAGS}" --expt-extended-lambda --expt-relaxed-constexpr 211else 212 PETSC_RAJACOMPILE_SINGLE = ${CXX} -o $*.o -c ${CXX_FLAGS} ${CXXFLAGS} ${CXXCPPFLAGS} 213endif 214 215LDLIBS += $(PRELIBS) $(PETSC_LIB) $(LIBS) 216 217% : %.c 218 $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ 219% : %.F90 220 $(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@ 221% : %.kokkos.cxx 222 $(LINK.kokkos.cxx) $^ $(LOADLIBES) $(LDLIBS) -o $@ 223% : %.cxx 224 $(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@ 225% : %.hip.cxx 226 $(LINK.hip.cxx) $^ $(LOADLIBES) $(LDLIBS) -o $@ 227 228# Shall we compile *.c to *.o and then link *.o to executables in two separate steps? 229SEPARATE_COMPILE_LINK = 230 231# See MR !2750 232ifneq (,$(findstring -TP,$(PCC_FLAGS))) 233 SEPARATE_COMPILE_LINK = 1 234endif 235 236# To avoid warnings when compiling *.c with sycl compilers 237# icx -fsycl -o ex1 ex1.c .. 238# icx: warning: treating 'c' input as 'c++' when -fsycl is used [-Wexpected-file-type] 239ifneq (,$(findstring -fsycl,$(PCC_LINKER_FLAGS))) 240 SEPARATE_COMPILE_LINK = 1 241endif 242 243ifdef SEPARATE_COMPILE_LINK 244% : %.c 245 $(subst $@, $@.o, ${PETSC_COMPILE_SINGLE}) $< 246 ${CLINKER} -o $@ $@.o $(filter-out $@.o $<,$^) $(LOADLIBES) $(LDLIBS) 247endif 248 249# We don't have % : %.cu target as we can't use nvcc as linker - due to difference in linker options [wrt CLINKER etc.]. For example, nvcc does not accept -Wl,-rpath 250# % : %.cu 251 252# makes an Emscripten https://emscripten.org/ executable from a PETSc C main program 253# See config/examples/arch-ci-linux-emcc.py for an example of building the PETSc libraries with Emscripten 254# node drops a variety of silly crums that are not all trivially blockable 255# 256ifneq (,$(findstring emcc,$(CC))) 257% : %.c 258 $(subst $@, $@.o, ${PETSC_COMPILE_SINGLE}) $< 259 ${CLINKER} -s MAIN_MODULE -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=1 -s ALLOW_MEMORY_GROWTH $(EXEFLAGS) -o $@.js $@.o $(PETSC_LIB) 260 -@printf '#!/usr/bin/env sh\nnode --redirect-warnings=/dev/null $@.js $$* | grep -v "Heap resize call from" ' > $@ 261 -@chmod u+x $@ 262endif 263 264help-applications: 265 -@echo "" 266 -@echo "make applicationname - compiles applicationname.[c,cxx,F,F90] file into an executable" 267 -@echo "make clean - delete any object files and executables in the current directory" 268 -@echo "make libs - rebuilds any needed changes to the PETSc libraries" 269 -@echo "" 270 271include ${PETSC_DIR}/lib/petsc/conf/rules_doc.mk 272