Skip to content

Commit

Permalink
Merge pull request #726 from CEED/jeremy/petsc-ex-build
Browse files Browse the repository at this point in the history
Refactor petsc examples to reduce redundant code
  • Loading branch information
jeremylt committed Apr 14, 2021
2 parents bcb0187 + bf0f51f commit caa531a
Show file tree
Hide file tree
Showing 41 changed files with 2,955 additions and 3,750 deletions.
66 changes: 44 additions & 22 deletions examples/petsc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,61 @@ CEED_DIR ?= ../..
ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc

CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
CFLAGS = -std=c99 $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) $(call pkgconf, --cflags-only-other $(PETSc.pc)) $(OPT)
CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc))
CFLAGS = -std=c99 \
$(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
$(call pkgconf, --cflags-only-other $(PETSc.pc)) \
$(OPT)
CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
$(call pkgconf, --variable=cflags_dep $(PETSc.pc))
LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm

area.c := area.c
area := $(area.c:%.c=%)
OBJDIR := build
SRCDIR := src

bps.c := bps.c
bps := $(bps.c:%.c=%)
utils.c := $(sort $(wildcard $(SRCDIR)/*.c))

bpsraw.c := bpsraw.c
bpsraw := $(bpsraw.c:%.c=%)
all: area bps bpsraw bpssphere multigrid

bpssphere.c := bpssphere.c
bpssphere := $(bpssphere.c:%.c=%)
area.c := area.c $(utils.c)
area.o = $(area.c:%.c=$(OBJDIR)/%.o)
area: $(area.o) | $(PETSc.pc) $(ceed.pc)
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@

multigrid.c := multigrid.c
multigrid := $(multigrid.c:%.c=%)
bps.c := bps.c $(utils.c)
bps.o = $(bps.c:%.c=$(OBJDIR)/%.o)
bps: $(bps.o) | $(PETSc.pc) $(ceed.pc)
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@

all: $(area) $(bps) $(bpsraw) $(bpssphere) $(multigrid)
$(area): | $(PETSc.pc) $(ceed.pc)
$(bps): | $(PETSc.pc) $(ceed.pc)
$(bpsraw): | $(PETSc.pc) $(ceed.pc)
$(bpssphere): | $(PETSc.pc) $(ceed.pc)
$(multigrid): | $(PETSc.pc) $(ceed.pc)
bpsraw.c := bpsraw.c $(utils.c)
bpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o)
bpsraw: $(bpsraw.o) | $(PETSc.pc) $(ceed.pc)
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@

bpssphere.c := bpssphere.c $(utils.c)
bpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o)
bpssphere: $(bpssphere.o) | $(PETSc.pc) $(ceed.pc)
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@

multigrid.c := multigrid.c $(utils.c)
multigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
multigrid: $(multigrid.o) | $(PETSc.pc) $(ceed.pc)
$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@

.SECONDEXPANSION: # to expand $$(@D)/.DIR
%/.DIR :
@mkdir -p $(@D)
@touch $@

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

$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)

# Rules for building the examples
%: %.c
$(call quiet,CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(CEED_LDFLAGS) $(abspath $<) -o $@ \
$(LDLIBS)
#%: %.c

print: $(PETSc.pc) $(ceed.pc)
$(info CC : $(CC))
Expand All @@ -69,7 +89,7 @@ print: $(PETSc.pc) $(ceed.pc)
@true

clean:
$(RM) $(area) $(bps) $(bpsraw) $(bpssphere) $(multigrid)
$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid

$(PETSc.pc):
$(if $(wildcard $@),,$(error \
Expand All @@ -78,3 +98,5 @@ $(PETSc.pc):
.PHONY: all print clean

pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')

-include $(src.o:%.o=%.d)
18 changes: 8 additions & 10 deletions examples/petsc/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## libCEED + PETSc Examples

### CEED bakeoff problems - bpsraw
### CEED bakeoff problems with raw mesh management - bpsraw

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

To build, run `make bpsraw`

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

#### Running a suite

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

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

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. The
resulting log file can be read by the Python plotting scripts in `benchmarks/`.
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.
The resulting log file can be read by the Python plotting scripts in `benchmarks/`.

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

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

To build, run `make multigrid`

Expand Down

0 comments on commit caa531a

Please sign in to comment.