Example Petsc Makefile
From charlesreid1
The following is an example Makefile that compiles an object-oriented C++ CFD solver that uses Petsc.
The example program is a Laplace solver.
# To begin with, a default target must be defined.
# The default is the driver contained in the
# Laplace.cc file.
default: Laplace
# Define the path to the Petsc install directory
PETSC_DIR=/Users/charles/pkg/petsc-3.0.0
# Include Petsc-defined variables
include ${PETSC_DIR}/conf/base
# These rules define how to compile the cc file.
# Then the Makefile links the executable to
# the output (.o file).
SRC_FILES = \
BoundaryCondition.cc \
BoundaryConditionFactory.cc \
Field.cc \
FileIO.cc \
JacobiSolver.cc \
Timer.cc \
TimerFactory.cc \
GmresSolver.cc \
OBJ_FILES = $(SRC_FILES:%.cc=%.o)
DRIVER_SRC = \
Laplace.cc \
# Make macros:
# $< = first input
# $^ = inputs
# $@ = outputs
# Define a make target for non-Petsc source files: any .cc file is compiled into a .o file
%.o: %.cc
g++ -c -Wall -I. $< -o $@
# Define make target for the GMRES solver class, which uses Petsc. This must use the ${PETSC_COMPILE} variable
# to include
GmresSolver.o: GmresSolver.cc
${PETSC_COMPILE} -c -Wall $< -o $@
# Define make target for both Petsc and non-Petsc objects
objects: $(OBJ_FILES)
# Define make target for linking the objects with the driver
# The ${CLINKER} variable is defined by Petsc. The "-" prefix is also very important.
# If you compile Petsc to use C, ${CLINKER} is mpicc. If you compile Petsc to use C++, ${CLINKER} is mpic++.
Laplace: Laplace.cc $(OBJ_FILES)
-${CLINKER} $< -o bin.x $(OBJ_FILES) ${PETSC_KSP_LIB} -I$(PETSC_DIR)/include
| Scientific Computing Topics in scientific computing.
Numerical Software: Lapack · Sundials · Matlab · Octave · FFTW Petsc · Example Petsc Makefile · Trilinos · Hypre · Ginac · Gnuplot
Python: Numpy · Scipy · Pandas · Matplotlib · Python Sundials · Py4Sci Scikit-learn: Sklearn · Skimage
|