Skip to content

Commit caa531a

Browse files
authored
Merge pull request #726 from CEED/jeremy/petsc-ex-build
Refactor petsc examples to reduce redundant code
2 parents bcb0187 + bf0f51f commit caa531a

41 files changed

Lines changed: 2955 additions & 3750 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/petsc/Makefile

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,61 @@ CEED_DIR ?= ../..
2424
ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
2525

2626
CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
27-
CFLAGS = -std=c99 $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) $(call pkgconf, --cflags-only-other $(PETSc.pc)) $(OPT)
28-
CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc))
27+
CFLAGS = -std=c99 \
28+
$(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
29+
$(call pkgconf, --cflags-only-other $(PETSc.pc)) \
30+
$(OPT)
31+
CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
32+
$(call pkgconf, --variable=cflags_dep $(PETSc.pc))
2933
LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
3034
LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
3135
LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm
3236

33-
area.c := area.c
34-
area := $(area.c:%.c=%)
37+
OBJDIR := build
38+
SRCDIR := src
3539

36-
bps.c := bps.c
37-
bps := $(bps.c:%.c=%)
40+
utils.c := $(sort $(wildcard $(SRCDIR)/*.c))
3841

39-
bpsraw.c := bpsraw.c
40-
bpsraw := $(bpsraw.c:%.c=%)
42+
all: area bps bpsraw bpssphere multigrid
4143

42-
bpssphere.c := bpssphere.c
43-
bpssphere := $(bpssphere.c:%.c=%)
44+
area.c := area.c $(utils.c)
45+
area.o = $(area.c:%.c=$(OBJDIR)/%.o)
46+
area: $(area.o) | $(PETSc.pc) $(ceed.pc)
47+
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
4448

45-
multigrid.c := multigrid.c
46-
multigrid := $(multigrid.c:%.c=%)
49+
bps.c := bps.c $(utils.c)
50+
bps.o = $(bps.c:%.c=$(OBJDIR)/%.o)
51+
bps: $(bps.o) | $(PETSc.pc) $(ceed.pc)
52+
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
4753

48-
all: $(area) $(bps) $(bpsraw) $(bpssphere) $(multigrid)
49-
$(area): | $(PETSc.pc) $(ceed.pc)
50-
$(bps): | $(PETSc.pc) $(ceed.pc)
51-
$(bpsraw): | $(PETSc.pc) $(ceed.pc)
52-
$(bpssphere): | $(PETSc.pc) $(ceed.pc)
53-
$(multigrid): | $(PETSc.pc) $(ceed.pc)
54+
bpsraw.c := bpsraw.c $(utils.c)
55+
bpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o)
56+
bpsraw: $(bpsraw.o) | $(PETSc.pc) $(ceed.pc)
57+
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
58+
59+
bpssphere.c := bpssphere.c $(utils.c)
60+
bpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o)
61+
bpssphere: $(bpssphere.o) | $(PETSc.pc) $(ceed.pc)
62+
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
63+
64+
multigrid.c := multigrid.c $(utils.c)
65+
multigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
66+
multigrid: $(multigrid.o) | $(PETSc.pc) $(ceed.pc)
67+
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
68+
69+
.SECONDEXPANSION: # to expand $$(@D)/.DIR
70+
%/.DIR :
71+
@mkdir -p $(@D)
72+
@touch $@
5473

5574
# Quiet, color output
5675
quiet ?= $($(1))
5776

77+
$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
78+
$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
79+
5880
# Rules for building the examples
59-
%: %.c
60-
$(call quiet,CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(CEED_LDFLAGS) $(abspath $<) -o $@ \
61-
$(LDLIBS)
81+
#%: %.c
6282

6383
print: $(PETSc.pc) $(ceed.pc)
6484
$(info CC : $(CC))
@@ -69,7 +89,7 @@ print: $(PETSc.pc) $(ceed.pc)
6989
@true
7090

7191
clean:
72-
$(RM) $(area) $(bps) $(bpsraw) $(bpssphere) $(multigrid)
92+
$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid
7393

7494
$(PETSc.pc):
7595
$(if $(wildcard $@),,$(error \
@@ -78,3 +98,5 @@ $(PETSc.pc):
7898
.PHONY: all print clean
7999

80100
pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
101+
102+
-include $(src.o:%.o=%.d)

examples/petsc/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## libCEED + PETSc Examples
22

3-
### CEED bakeoff problems - bpsraw
3+
### CEED bakeoff problems with raw mesh management - bpsraw
44

5-
This code solves the CEED bakeoff problems on a structured grid generated and
6-
referenced using only low-level communication primitives.
5+
This code solves the CEED bakeoff problems on a structured grid generated and referenced using only low-level communication primitives.
76

87
To build, run `make bpsraw`
98

@@ -29,21 +28,20 @@ In addition to the common arguments, the following arguments may be set:
2928

3029
#### Running a suite
3130

32-
Some run-time arguments can be passed lists, which allows a single `mpiexec` invocation
33-
to run many experiments. For example
31+
Some run-time arguments can be passed lists, which allows a single `mpiexec` invocation to run many experiments.
32+
For example
3433

3534
mpiexec -n 64 ./bps -problem bp1,bp2,bp3,bp4 -degree 2,3,5,7 \
3635
-ceed /cpu/self/opt/serial,/cpu/self/xsmm/serial,/cpu/self/xsmm/blocked \
3736
-local_nodes 600,20000 | tee bps.log
3837

39-
which will sample from the `4*4*3=48` specified combinations, each of which will run a
40-
problem-size sweep of 600, 1200, 2400, 4800, 9600, 192000 FEM nodes per MPI rank. The
41-
resulting log file can be read by the Python plotting scripts in `benchmarks/`.
38+
which will sample from the `4*4*3=48` specified combinations, each of which will run a problem-size sweep of 600, 1200, 2400, 4800, 9600, 192000 FEM nodes per MPI rank.
39+
The resulting log file can be read by the Python plotting scripts in `benchmarks/`.
4240

4341
### CEED bakeoff problems with DMPlex and PCMG - multigrid
4442

45-
This code solves the CEED bakeoff problems on a unstructured grid using DMPlex
46-
with p-multigrid implemented in PCMG. This example requires a PETSc version later than 3.11.3.
43+
This code solves the CEED bakeoff problems on a unstructured grid using DMPlex with p-multigrid implemented in PCMG.
44+
This example requires a PETSc version later than 3.11.3.
4745

4846
To build, run `make multigrid`
4947

0 commit comments

Comments
 (0)