From charlesreid1

Revision as of 10:37, 1 December 2010 by Admin (talk | contribs) (Created page with "The following is an example Makefile that compiles an object-oriented CFD solver that uses Petsc. The example program is a Laplace solver. <syntaxhighlight lang="make"> # To b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The following is an example Makefile that compiles an object-oriented 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

GmresSolver.o: GmresSolver.cc
    g++ -c -Wall -I. -I$(PETSC_DIR) -I$(PETSC_DIR)/bmake-darwin9.5.0-c-opt -I$(PETSC_DIR)/inc



# 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} Laplace.cc -o bin.x $(OBJ_FILES) ${PETSC_KSP_LIB} -I$(PETSC_DIR)/include