Installing PETSc 2.2.1 on Mac OS X 10.3

PETSc is the Portable, Extensible Toolkit for Scientific Computation (PETSc homepage). It utilizes the Basic Linear Algebra Subprograms package (BLAS) and the Linear Algebra Package (LAPACK).

Here are the steps I took to install PETSc on a Mac running OS X 10.3:

  1. Download and install MPICH, which is a message-passing interface (MPI) implementation. I wrote up some notes here.

  2. Download and unzip/untar the PETSc package to /usr/local/petsc/ (or wherever you want to put PETSc). Unzip/untar the download from /usr/local/petsc/ as follows:

    sudo gunzip -c petsc.tar.gz | sudo tar -xof -

  3. Set the PETSC_DIR and PETSC_ARCH environmental variables. This can be done by adding the following lines to ~/.bash_profile and/or ~./bashrc:

    # set environmental variables for PETSc
    export PETSC_DIR=/usr/local/petsc/petsc-2.2.1/
    export PETSC_ARCH=macx


    Don't forget to source ~/.bash_profile and/or ~/.bashrc after making the change. Alternatively, you can set the variables each time from the command line:

    PETSC_DIR=`pwd` ; export PETSC_DIR
    PETSC_ARCH=macx ; export PETSC_ARCH


  4. From within the PETSc directory, run the configure script with flags to use gcc, g++, f77, and the BLAS and LAPACK libraries included in Apple's vecLib:

    sudo python ./config/configure.py --with-blas-lapack-lib="-framework vecLib" --with-mpi-dir=/usr/local/mpich/mpich-1.2.6 --with-cc=gcc --with-cxx=g++ --with-fc=g77

  5. Build with the debug C++ target and run the test script:

    sudo make BOPT=g_c++
    sudo make BOPT=g_c++ test


  6. Build and test with whatever other targets you want, e.g. the optimized C++ target BOPT=O_c++, the debug C target BOPT=g, or the optimized C target BOPT=O.

To allow the test script to utilize graphics, run it in an X11 terminal. Note also that, if you wanted to, you could build PETSc with the the Automatically Tuned Linear Algebra Software (atlas) package available through Fink. The atlas package includes BLAS and LAPACK (at least large parts of them).