Debian Codegraph @

examples/petsc/makefile

raw
1 # Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2 # at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 # LICENSE and NOTICE for details. LLNL-CODE-806117.
4 #
5 # This file is part of the MFEM library. For more information and source code
6 # availability visit https://mfem.org.
7 #
8 # MFEM is free software; you can redistribute it and/or modify it under the
9 # terms of the BSD-3 license. We welcome feedback and contributions, see file
10 # CONTRIBUTING.md for details.
11
12 # Use the MFEM build directory
13 MFEM_DIR ?= ../..
14 MFEM_BUILD_DIR ?= ../..
15 MFEM_INSTALL_DIR ?= ../../mfem
16 SRC = $(if $(MFEM_DIR:../..=),$(MFEM_DIR)/examples/petsc/,)
17 CONFIG_MK = $(or $(wildcard $(MFEM_BUILD_DIR)/config/config.mk),\
18 $(wildcard $(MFEM_INSTALL_DIR)/share/mfem/config.mk))
19
20 MFEM_LIB_FILE = mfem_is_not_built
21 -include $(CONFIG_MK)
22
23 SEQ_EXAMPLES =
24 PAR_EXAMPLES = ex1p ex2p ex3p ex4p ex5p ex6p ex9p ex10p
25 ifeq ($(MFEM_USE_SLEPC),YES)
26 PAR_EXAMPLES += ex11p
27 endif
28 ifeq ($(MFEM_USE_MPI),NO)
29 EXAMPLES = $(SEQ_EXAMPLES)
30 else
31 EXAMPLES = $(PAR_EXAMPLES)
32 endif
33 RC_FILES = $(patsubst $(SRC)%,%,$(wildcard $(SRC)rc_*))
34
35 .SUFFIXES:
36 .SUFFIXES: .o .cpp .mk
37 .PHONY: all clean clean-build clean-exec
38
39 # Remove built-in rule
40 %: %.cpp
41
42 # Replace the default implicit rule for *.cpp files
43 %: $(SRC)%.cpp $(MFEM_LIB_FILE) $(CONFIG_MK)
44 $(MFEM_CXX) $(MFEM_FLAGS) $< -o $@ $(MFEM_LIBS)
45
46 all: $(EXAMPLES)
47
48 # Examples depend on their corresponding rc_* files:
49 make-rc-rule = $(1): | $(filter rc_$(1)%,$(RC_FILES))
50 $(foreach ex,$(EXAMPLES),$(eval $(call make-rc-rule,$(ex))))
51
52 # Rules to copy the rc_* files when building out-of-source:
53 ifneq ($(SRC),)
54 $(RC_FILES): %: $(SRC)%
55 cp -pf $(<) .
56 endif
57
58 ifeq ($(MFEM_USE_PETSC),NO)
59 $(EXAMPLES):
60 $(error MFEM is not configured with PETSC)
61 endif
62
63 MFEM_TESTS = EXAMPLES
64 include $(MFEM_TEST_MK)
65
66 # Testing: Parallel runs
67 RUN_MPI = $(MFEM_MPIEXEC) $(MFEM_MPIEXEC_NP) $(MFEM_MPI_NP)
68 TESTNAME = Parallel PETSc example
69 TESTNAME_CUDA = Parallel CUDA PETSc example
70 TESTNAME_HIP = Parallel HIP PETSc example
71 %-test-par: %
72 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME))
73
74
75 # Testing PETSc execution options.
76 EX1_ARGS_W := -m ../../data/amr-quad.mesh --usepetsc
77 EX1_ARGS_P := -m ../../data/amr-quad.mesh --usepetsc --petscopts rc_ex1p
78 EX1_ARGS_CUDA := -m ../../data/star.mesh --usepetsc --partial-assembly --device cuda --petscopts rc_ex1p_device
79 EX1_ARGS_CUDAAMG := -m ../../data/star.mesh --usepetsc --device cuda --petscopts rc_ex1p_deviceamg
80 EX1_ARGS_HIP := -m ../../data/star.mesh --usepetsc --partial-assembly --device hip --petscopts rc_ex1p_device
81 EX1_ARGS_HIPAMG := -m ../../data/star.mesh --usepetsc --device hip --petscopts rc_ex1p_deviceamg
82 EX2_ARGS := -m ../../data/beam-quad.mesh --usepetsc --petscopts rc_ex2p
83 EX2_ARGS_BDDC := -m ../../data/beam-tri.mesh --usepetsc --nonoverlapping --petscopts rc_ex2p_bddc
84 EX2_ARGS_ASM := -m ../../data/beam-quad.mesh --usepetsc --petscopts rc_ex2p_asm
85 EX3_ARGS_BDDC_2D := -m ../../data/klein-bottle.mesh -o 2 -f 0.1 --usepetsc --petscopts rc_ex3p_bddc --nonoverlapping
86 EX3_ARGS_BDDC_3D := -m ../../data/amr-hex.mesh -rs 1 -rp 0 -o 2 -f 0.1 --usepetsc --petscopts rc_ex3p_bddc --nonoverlapping
87 EX4_ARGS := -m ../../data/klein-bottle.mesh -o 2 --usepetsc --petscopts rc_ex4p_bddc --nonoverlapping
88 EX4_HYB_ARGS := -m ../../data/klein-bottle.mesh -o 2 --usepetsc --petscopts rc_ex4p_bddc --nonoverlapping --hybridization
89 EX5_BDDC_LB_ARGS := -m ../../data/star.mesh --usepetsc -o 0 --petscopts rc_ex5p_bddc --nonoverlapping --local-bdr
90 EX5_BDDC_GB_ARGS := -m ../../data/star.mesh --usepetsc -o 0 --petscopts rc_ex5p_bddc --nonoverlapping
91 EX5_FSPL_ARGS := -m ../../data/beam-tet.mesh --usepetsc -o 0 --petscopts rc_ex5p_fieldsplit
92 EX6_ARGS := -m ../../data/amr-quad.mesh --usepetsc
93 EX6_NONOVL_ARGS := -m ../../data/amr-quad.mesh --usepetsc --nonoverlapping
94 EX9_E_ARGS := -m ../../data/periodic-hexagon.mesh --usepetsc --petscopts rc_ex9p_expl -dt 0.1
95 EX9_ES_ARGS := -m ../../data/periodic-hexagon.mesh --usepetsc --petscopts rc_ex9p_expl --no-step
96 EX9_ES_ARGS_CUDA := -m ../../data/periodic-hexagon.mesh --usepetsc --petscopts rc_ex9p_expl_device --no-step --partial-assembly --device cuda
97 EX9_ES_ARGS_HIP := -m ../../data/periodic-hexagon.mesh --usepetsc --petscopts rc_ex9p_expl_device --no-step --partial-assembly --device hip
98 EX9_IS_ARGS := -m ../../data/periodic-hexagon.mesh --usepetsc --petscopts rc_ex9p_impl --implicit -tf 0.5
99 EX10_ARGS := -m ../../data/beam-quad.mesh --usepetsc --petscopts rc_ex10p -tf 30 -s 3 -rs 2 -dt 3
100 EX10_MF_ARGS := -m ../../data/beam-quad.mesh --usepetsc --petscopts rc_ex10p_mf -tf 6 -s 3 -rs 0 -dt 3
101 EX10_MFOP_ARGS := -m ../../data/beam-quad.mesh --usepetsc --petscopts rc_ex10p_mfop -tf 6 -s 3 -rs 0 -dt 3
102 EX10_JFNK_ARGS := -m ../../data/beam-quad.mesh --usepetsc --petscopts rc_ex10p_jfnk --jfnk -tf 6 -s 3 -rs 0 -dt 3
103 EX11_ARGS_SINV := -m ../../data/star.mesh --useslepc
104 EX11_ARGS_LOBPCG := -m ../../data/star.mesh --useslepc --slepcopts rc_ex11p_lobpcg
105 EX11_ARGS_LOBPCG_CUDA := -m ../../data/star.mesh --useslepc --slepcopts rc_ex11p_lobpcg_device --device cuda
106 EX11_ARGS_LOBPCG_HIP := -m ../../data/star.mesh --useslepc --slepcopts rc_ex11p_lobpcg_device --device hip
107 EX11_ARGS_GD := -m ../../data/star.mesh --useslepc --slepcopts rc_ex11p_gd
108
109 ex1p-test-par: ex1p
110 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX1_ARGS_W))
111 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX1_ARGS_P))
112 ifeq ($(MFEM_USE_CUDA),YES)
113 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_CUDA),$(EX1_ARGS_CUDA))
114 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_CUDA),$(EX1_ARGS_CUDAAMG))
115 endif
116 ifeq ($(MFEM_USE_HIP),YES)
117 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_HIP),$(EX1_ARGS_HIP))
118 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_HIP),$(EX1_ARGS_HIPAMG))
119 endif
120 ex2p-test-par: ex2p
121 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX2_ARGS))
122 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX2_ARGS_BDDC))
123 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX2_ARGS_ASM))
124 ex3p-test-par: ex3p
125 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX3_ARGS_BDDC_2D))
126 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX3_ARGS_BDDC_3D))
127 ex4p-test-par: ex4p
128 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX4_ARGS))
129 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX4_HYB_ARGS))
130 ex5p-test-par: ex5p
131 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX5_BDDC_LB_ARGS))
132 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX5_BDDC_GB_ARGS))
133 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX5_FSPL_ARGS))
134 ex6p-test-par: ex6p
135 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX6_ARGS))
136 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX6_NONOVL_ARGS))
137 ex9p-test-par: ex9p
138 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX9_E_ARGS))
139 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX9_ES_ARGS))
140 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX9_IS_ARGS))
141 ifeq ($(MFEM_USE_CUDA),YES)
142 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_CUDA),$(EX9_ES_ARGS_CUDA))
143 endif
144 ifeq ($(MFEM_USE_HIP),YES)
145 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_HIP),$(EX9_ES_ARGS_HIP))
146 endif
147 ex10p-test-par: ex10p
148 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX10_ARGS))
149 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX10_MF_ARGS))
150 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX10_MFOP_ARGS))
151 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX10_JFNK_ARGS))
152 ifeq ($(MFEM_USE_SLEPC),YES)
153 ex11p-test-par: ex11p
154 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX11_ARGS_SINV))
155 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX11_ARGS_LOBPCG))
156 ifeq ($(MFEM_USE_CUDA),YES)
157 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_CUDA),$(EX11_ARGS_LOBPCG_CUDA))
158 endif
159 # SLEPc does not support BVSVEC with HIP
160 #ifeq ($(MFEM_USE_HIP),YES)
161 # @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME_HIP),$(EX11_ARGS_LOBPCG_HIP))
162 #endif
163 @$(call mfem-test,$<, $(RUN_MPI), $(TESTNAME),$(EX11_ARGS_GD))
164 endif
165
166 # Testing: "test" target and mfem-test* variables are defined in config/test.mk
167
168 # Generate an error message if the MFEM library is not built and exit
169 $(MFEM_LIB_FILE):
170 $(error The MFEM library is not built)
171
172 clean: clean-build clean-exec
173
174 clean-build:
175 rm -f *.o *~ $(SEQ_EXAMPLES) $(PAR_EXAMPLES)
176 rm -rf *.dSYM *.TVD.*breakpoints
177 ifneq ($(SRC),)
178 rm -f $(RC_FILES)
179 endif
180
181 clean-exec:
182 @rm -rf mesh.* sol.* sol_p.* sol_u.* Example5*
183 @rm -f ex9-mesh.* ex9-init.* ex9-final.* Example9*
184 @rm -f deformed.* velocity.* elastic_energy.* mode_*