15.2.1. Sample Makefiles

Up: Contents Next: Limitations Previous: PETSc Flags

Maintaining portable PETSc makefiles is very simple. In Figures 21 , 22 , and 23 we present three sample makefiles.

The first is a ``minimum'' makefile for maintaining a single program that uses the PETSc libraires. The most important line in this makefile is the line starting with include:

   include ${PETSC_DIR}/bmake/${PETSC_ARCH}/base 
This line includes other makefiles that provide the needed definitions and rules for the particular base PETSc installation (specified by ${}PETSC_DIR) and architecture (specified by ${}PETSC_ARCH). (See Running PETSc Programs for information on setting these environmental variables.) As listed in the sample makefile, the appropriate include file is automatically completely specified; the user should not alter this statement within the makefile.


   ALL: ex2 

CFLAGS = FFLAGS = CPPFLAGS = FPPFLAGS =

include ${PETSC_DIR}/bmake/${PETSC_ARCH}/base

ex2: ex2.o chkopts ${CLINKER} -o ex2 ex2.o ${PETSC_LIB} ${RM} ex2.o


Figure 21: Sample PETSc Makefile for a Single Program

Note that the variable ${}PETSC_LIB (as listed on the link line in the above makefile) specifies all of the various PETSc libraries in the appropriate order for correct linking. For users who employ only a specific PETSc component, can use alternative variables like ${}PETSC_SYS_LIB, ${}PETSC_VEC_LIB, ${}PETSC_MAT_LIB, ${}PETSC_DM_LIB, ${}PETSC_SLES_LIB, ${}PETSC_SNES_LIB or ${}PETSC_TS_LIB.

The second sample makefile, given in Figure 22 , controls the generation of several example programs.


   CFLAGS   =  
   FFLAGS   =  
   CPPFLAGS = 
   FPPFLAGS = 

RUNEXAMPLES_1 = runex1 runex2 RUNEXAMPLES_2 = runex4 RUNEXAMPLES_3 = runex3 EXAMPLESC = ex1.c ex2.c ex4.c EXAMPLESF = ex3.F EXAMPLES_1 = ex1 ex2 EXAMPLES_2 = ex4 EXAMPLES_3 = ex3

ex1: ex1.o -${CLINKER} -o ex1 ex1.o ${PETSC_LIB} ${RM} ex1.o ex2: ex2.o -${CLINKER} -o ex2 ex2.o ${PETSC_LIB} ${RM} ex2.o ex3: ex3.o -${FLINKER} -o ex3 ex3.o ${PETSC_FORTRAN_LIB} ${PETSC_LIB} ${RM} ex3.o ex4: ex4.o -${CLINKER} -o ex4 ex4.o ${PETSC_LIB} ${RM} ex4.o

runex1: -@${MPIRUN} ex1 runex2: -@${MPIRUN} -np 2 ex2 -mat_seqdense -optionsleft runex3: -@${MPIRUN} ex3 -v -log_summary runex4: -@${MPIRUN} -np 4 ex4 -trdump

include ${PETSC_DIR}/bmake/${PETSC_ARCH}/base


Figure 22: Sample PETSc Makefile for Several Example Programs

Again, the most important line in this makefile is the include line that includes the files defining all of the macro variables. Some additional variables that can be used in the makefile are defined as follows:


Note that the PETSc example programs are divided into several categories, which currently include:

We next list in Figure 23 a makefile that maintains a PETSc library. Although most users do not need to understand or deal with such makefiles, they are also easily used.


   ALL: lib 

CFLAGS = SOURCEC = sp1wd.c spinver.c spnd.c spqmd.c sprcm.c SOURCEF = degree.f fnroot.f genqmd.f qmdqt.f rcm.f fn1wd.f gen1wd.f \ genrcm.f qmdrch.f rootls.f fndsep.f gennd.f qmdmrg.f qmdupd.f SOURCEH = OBJSC = sp1wd.o spinver.o spnd.o spqmd.o sprcm.o OBJSF = degree.o fnroot.o genqmd.o qmdqt.o rcm.o fn1wd.o gen1wd.o \ genrcm.o qmdrch.o rootls.o fndsep.o gennd.o qmdmrg.o qmdupd.o LIBBASE = libpetscmat MANSEC = Mat

include ${PETSC_DIR}/bmake/${PETSC_ARCH}/base


Figure 23: Sample PETSc Makefile for Library Maintenance

The library's name is libpetscmat.a, and the source files being added to it are indicated by SOURCEC (for C files) and SOURCEF (for Fortran files). Note that the OBJSF and OBJSC are identical to SOURCEF and SOURCEC, respectively, except they use the suffix .o rather than .c or .f.

The variable MANSEC indicates that any manual pages generated from this source should be included in the Mat section.


Up: Contents Next: Limitations Previous: PETSc Flags