PETSc Installation

PETSc (Portable, Extensible Toolkit for Scientific Computing) is a library of scalable linear and non-linear equation solvers and ODE solvers, developed and maintained at the Mathematics & Computer Science Division at Argonne National Laboratory. The official webpage of PETSc provides the download and installation instructions, as well as extensive documentation. Most of the codes I work with use the TS module of PETsc for advanced high-order time-integration schemes and it will be useful to briefly go through the documentation for this module to understand and utilize them:

  • User Manual (PDF) (Chapter 6 - TS: Scalable ODE and DAE Solvers)
  • TS Examples

  • To download the official or development releases of PETSc, go here.

    Complete installation instructions, including all options, are available here. This page contains brief instructions that I find useful to quickly download and install PETSc to use with the codes I am working with.


    With Bitbucket account and SSH keys set up:

    git clone


    git clone

    The branch master should be compiled and used, unless some feature that is needed is on some other branch. Visit PETSC's Bitbucket page for details of branches, commits, etc.


    The following steps should install PETSc:

  • Set environment variables PETSC_DIR and PETSC_ARCH (Can be set in .bashrc too)
    • export PETSC_DIR=/path/to/petsc/ (Eg. PETSC_DIR=/home/ghosh/petsc)
      export PETSC_ARCH=(name of build) (Eg. arch-debug or arch-opt. It can be anything)
  • Move to the PETSc directory (cd $PETSC_DIR)

  • Configure with options for debug (slow) or optimized (fast)
    Example: If GNU compilers exist but PETSc needs to download and compile MPICH,
      ./configure --with-cc=gcc --with-fc=gfortran --download-mpich=1 --with-shared-libraries --with-debugging=1 (debug)
      ./configure --with-cc=gcc --with-fc=gfortran --download-mpich=1 --with-shared-libraries --with-debugging=0 (optimized)
    Example: If MPICH already exists and PETSc needs to use that,
      ./configure --with-cc=mpicc --with-fc=mpif90 -with-cxx=mpicxx --with-shared-libraries --with-debugging=1 (debug)
      ./configure --with-cc=mpicc --with-fc=mpif90 -with-cxx=mpicxx --with-shared-libraries --with-debugging=0 (optimized)
    Note: PETSc can download and compile additional packages by adding --download-packagename=yes or use existing installations of those packages --with-packagename-include=/path/to/package/include and --with-packagename-lib=/path/to/package/lib or --with-packagename-dir=/path/to/package/ (use --help to see a list of these options and packages that PETSc can download). This page has examples of installing PETSc with downloading or using existing installations of HDF5, NetCDF and METIS packages.

  • Compilation
      make all
      make test

    Some machine specific configure commands

  • Vesta/Mira (ALCF IBM BG/Q)
  • ./configure CC=`which mpicc` CXX=`which mpicxx` FC=`which mpif90` --with-blas-lapack-lib="-L/soft/libraries/alcf/current/gcc/LAPACK/lib -llapack -L/soft/libraries/alcf/current/gcc/BLAS/lib -lblas" --with-shared-libraries=0

  • Fusion (LCRC)
  • ./configure --with-mpi-dir=/soft/mvapich2/1.4.1-intel-11.1.064 --with-shared-libraries=0
  • Quartz (With ParMETIS, Hypre and SuperLU)
  • ./configure --with-cc=mpicc --with-fc=mpif90 -with-cxx=mpicxx COPTFLAGS="-O2" FOPTFLAGS="-O2" CXXOPTFLAGS="-O2" --with-shared-libraries --with-debugging=0 --download-metis --download-parmetis --download-hypre --download-superlu --download-superlu_dist