ANL-95/11
PETSc Users Manual
Revision 3.1
by
S. Balay, K. Buschelman, V. Eijkhout, W. Gropp, D. Kaushik,
M. Knepley, L. Curfman McInnes, B. Smith, and H. Zhang
Mathematics and Computer Science Division, Argonne National Laboratory
March 2010
This work was supported by the Office of Advanced Scientific Computing Research,
Office of Science, U.S. Department of Energy, under Contract DE-AC02-06CH11357.
1
Availability of This Report
This report is available, at no cost, at http://www.osti.gov/bridge. It is also available
on paper to the U.S. Department of Energy and its contractors, for a processing fee, from:
U.S. Department of Energy
Office of Scientific and Technical Information
P.O. Box 62
Oak Ridge, TN 37831-0062
phone (865) 576-8401
fax (865) 576-5728
reports@adonis.osti.gov
Disclaimer
This report was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States
Government nor any agency thereof, nor UChicago Argonne, LLC, nor any of their employees or officers, makes any warranty, express
or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus,
product, or process disclosed, or represents that its use would not infringe privately owned rights. Reference herein to any specific
commercial product, process, or service by trade name, trademark, manufacturer, or otherwise, does not necessarily constitute or imply
its endorsement, recommendation, or favoring by the United States Government or any agency thereof. The views and opinions of
document authors expressed herein do not necessarily state or reflect those of the United States Government or any agency thereof,
Argonne National Laboratory, or UChicago Argonne, LLC.
About Argonne National Laboratory
Argonne is a U.S. Department of Energy laboratory managed by UChicago Argonne, LLC
under contract DE-AC02-06CH11357. The Laboratory’s main facility is outside Chicago,
at 9700 South Cass Avenue, Argonne, Illinois 60439. For information about Argonne
and its pioneering science and technology programs, see www.anl.gov.
2
Abstract:
This manual describes the use of PETSc for the numerical solution of partial differential equations and
related problems on high-performance computers. The Portable, Extensible Toolkit for Scientific Compu-
tation (PETSc) is a suite of data structures and routines that provide the building blocks for the implemen-
tation of large-scale application codes on parallel (and serial) computers. PETSc uses the MPI standard for
all message-passing communication.
PETSc includes an expanding suite of parallel linear, nonlinear equation solvers and time integrators that
may be used in application codes written in Fortran, C, and C++. PETSc provides many of the mechanisms
needed within parallel application codes, such as parallel matrix and vector assembly routines. The library
is organized hierarchically, enabling users to employ the level of abstraction that is most appropriate for
a particular problem. By using techniques of object-oriented programming, PETSc provides enormous
flexibility for users.
PETSc is a sophisticated set of software tools; as such, for some users it initially has a much steeper
learning curve than a simple subroutine library. In particular, for individuals without some computer science
background or experience programming in C or C++, it may require a significant amount of time to take
full advantage of the features that enable efficient software use. However, the power of the PETSc design
and the algorithms it incorporates may make the efficient implementation of many application codes simpler
than “rolling them” yourself.
• For many simple (or even relatively complicated) tasks a package such as Matlab is often the best tool;
PETSc is not intended for the classes of problems for which effective Matlab code can be written.
• PETSc should not be used to attempt to provide a “parallel linear solver” in an otherwise sequential
code. Certainly all parts of a previously sequential code need not be parallelized but the matrix
generation portion must be to expect any kind of reasonable performance. Do not expect to generate
your matrix sequentially and then “use PETSc” to solve the linear system in parallel.
Since PETSc is under continued development, small changes in usage and calling sequences of routines
may occur. PETSc is supported; see the web site http://www.mcs.anl.gov/petsc for information on contacting
support.
A http://www.mcs.anl.gov/petsc/petsc-as/publications may be found a list of publications and web sites
that feature work involving PETSc.
We welcome any additions to these pages.
3
4
Getting Information on PETSc:
On-line:
• Manual pages–example usage docs/index.html or http://www.mcs.anl.gov/petsc/petsc-as/documentation
In this manual:
• Basic introduction, page 17
• Assembling vectors, page 41; and matrices, 55
• Linear solvers, page 67
• Nonlinear solvers, page 83
• Timestepping (ODE) solvers, page 105
• Index, page 177
5