Quick Start Tutorial#
QQTW (Quickest Quick-start in The West)#
On systems where MPI and BLAS/LAPACK are installed, download PETSc and build with:
$ ./configure
$ make all check
Or to specify compilers and have PETSc download and install MPICH and BLAS/LAPACK 3 (when they are not already on your machine):
$ ./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack
$ make all check
Don’t need Fortran? Use --with-fortran-bindings=0
to reduce the build times. If you
are not using external packages that use Fortran (for
example, MUMPS requires Fortran) you can use
--with-fc=0
for even faster build times.
Encounter problems?
Read the error message from
configure
!Read help
./configure --help
.Refer to configuration faq (e.g. build PETSc without a Fortran compiler).
make
problems? Just copy/pastemake
command printed by theconfigure
footer including any
$PETSC_DIR
and$PETSC_ARCH
options. It may look similar to:
xxx=========================================================================xxx Configure stage complete. Now build PETSc libraries with: make PETSC_DIR=/Users/jacobfaibussowitsch/NoSync/petsc PETSC_ARCH=arch-darwin-c-debug all xxx=========================================================================xxx
Check the bug-reporting section.
Prerequisites#
Important
This tutorial assumes basic knowledge on the part of the user on how to navigate your system using the Command-Line Interface (CLI), a.k.a. “from the terminal”. Being a programmable solver suite, PETSc does not have a front-end Graphical User Interface, so any and all tutorial examples here will almost exclusively use the terminal.
While this tutorial will provide all commands necessary, it will not explain the usage or syntax of commands not directly implemented by PETSc. If you are unfamiliar with the command line, or would like to refresh your understanding, consider reviewing tutorials on basic Unix and shell usage.
Before beginning, make sure you have the following pre-requisites installed and up to date:
It is important to make sure that your compilers are correctly installed 2 (i.e. functional
and in your $PATH
). To test the compilers, run the following commands:
$ printf '#include<stdio.h>\nint main(){printf("cc OK!\\n");}' > t.c && cc t.c && ./a.out && rm -f t.c a.out
Note
While it is recommended that you have functional C++ and Fortran compilers installed, they are not directly required to run PETSc in its default state. If they are functioning, PETSc will automatically find them during the configure stage, however it is always useful to test them on your own.
$ printf '#include<iostream>\nint main(){std::cout<<"c++ OK!"<<std::endl;}' > t.cpp && c++ t.cpp && ./a.out && rm -f t.cpp a.out
$ printf 'program t\nprint"(a)","gfortran OK!"\nend program' > t.f90 && gfortran t.f90 && ./a.out && rm -f t.f90 a.out
If compilers are working, each command should print out <compiler_name> OK!
on the command
line.
Downloading Source#
See the download documentation for additional details.
With all dependencies installed, navigate to a suitable directory on your machine and pull the latest version of the PETSc library to your machine with git. The following commands will create a directory “petsc” inside the current directory and retrieve the latest release branch of the repository.
$ mkdir ~/projects
$ cd ~/projects
$ git clone -b release https://gitlab.com/petsc/petsc
$ cd petsc
Note
If git is not available - or if pre-generated Fortran stubs are required (i.e avoid download and install of sowing package - that also requires a C++ compiler) one can download a release tarball. See download documentation for additional details.
Warning
It is IMPERATIVE to install PETSc in a directory whose path does not contain any of the following special characters:
~ ! @ # $ % ^ & * ( ) ` ; < > ? , [ ] { } ‘ ” | (including spaces!)
While PETSc is equipped to handle these errors, other installed dependencies may not be so well protected.
The download process may take a few minutes to complete. Successfully running this command should yield a similar output:
$ git clone -b release https://gitlab.com/petsc/petsc.git petsc
Cloning into 'petsc'...
remote: Enumerating objects: 862597, done.
remote: Counting objects: 100% (862597/862597), done.
remote: Compressing objects: 100% (197622/197622), done.
remote: Total 862597 (delta 660708), reused 862285 (delta 660444)
Receiving objects: 100% (862597/862597), 205.11 MiB | 3.17 MiB/s, done.
Resolving deltas: 100% (660708/660708), done.
Updating files: 100% (7748/7748), done.
$ cd petsc
$ git pull # Not strictly necessary, but nice to check
Already up to date.
Configuration#
See install documentation for more details.
Next, PETSc needs to be configured using configure
for your system with your
specific options. This is the stage where users can specify the exact parameters to
customize their PETSc installation. Common configuration options are:
Specifying external packages to use or download automatically. PETSc can automatically download and install a wide range of other supporting software.
Setting various known machine quantities for PETSc to use such as known integral sizes, memory alignment, or additional compiler flags.
Important
You MUST specify all of your configuration options at this stage. In order to enable additional options or packages in the future, you will have to reconfigure your PETSc installation in a similar manner with these options enabled.
For a full list of available options call
$ ./configure --help
All PETSc options and flags follow the standard CLI formats --option-string=<value>
or
--option-string
, where <value>
is typically either 1
(for true) or 0
(for
false) or a directory path. Directory paths must be absolute (i.e. full path from the root
directory of your machine), but do accept environment variables as input.
From $PETSC_DIR
call the following configure
command to configure PETSc as well
as download and install MPICH and a BLAS/LAPACK 3 reference implementation on your system.
$ ./configure --download-mpich --download-fblaslapack
PETSc will begin configuring and printing its progress. A successful configure
will
have the following general structure as its output:
===============================================================================
Configuring PETSc to compile on your system
===============================================================================
TESTING: configureSomething from PETSc.something(config/PETSc/configurescript.py:lineNUM)
===============================================================================
Trying to download MPICH_DOWNLOAD_URL for MPICH
===============================================================================
===============================================================================
Running configure on MPICH; this may take several minutes
===============================================================================
===============================================================================
Running make on MPICH; this may take several minutes
===============================================================================
===============================================================================
Running make install on MPICH; this may take several minutes
===============================================================================
===============================================================================
Trying to download FBLASLAPACK_URL for FBLASLAPACK
===============================================================================
===============================================================================
Compiling FBLASLAPACK; this may take several minutes
===============================================================================
===============================================================================
Trying to download SOWING_DOWNLOAD_URL for SOWING
===============================================================================
===============================================================================
Running configure on SOWING; this may take several minutes
===============================================================================
===============================================================================
Running make on SOWING; this may take several minutes
===============================================================================
===============================================================================
Running make install on SOWING; this may take several minutes
===============================================================================
Compilers:
C Compiler: Location information and flags
C++ Compiler: Location information and flags
.
.
.
MPI:
Includes: Include path
Other Installed Packages:
.
.
.
PETSc:
PETSC_ARCH: {YOUR_PETSC_ARCH}
PETSC_DIR: {YOUR_PETSC_DIR}
.
.
.
.
xxx=========================================================================xxx
Configure stage complete. Now build PETSc libraries with (gnumake build):
make PETSC_DIR=/your/petsc/dir PETSC_ARCH=your-petsc-arch all
xxx=========================================================================xxx
Compilation#
After successfully configuring, build the binaries from source using the make
command. This stage may take a few minutes, and will consume a great deal of system
resources as the PETSc is compiled in parallel.
$ make all check
A successful make
will provide an output of the following structure:
-----------------------------------------
PETSC_VERSION_RELEASE
.
.
.
-----------------------------------------
#define SOME_PETSC_VARIABLE
.
.
.
-----------------------------------------
Installed Compiler, Package, and Library Information
.
.
.
=========================================
FC arch-darwin-c-debug/obj/sys/f90-mod/petscsysmod.o
FC arch-darwin-c-debug/obj/sys/fsrc/somefort.o
FC arch-darwin-c-debug/obj/sys/f90-src/fsrc/f90_fwrap.o
CC arch-darwin-c-debug/obj/sys/info/verboseinfo.o
CC arch-darwin-c-debug/obj/sys/info/ftn-auto/verboseinfof.o
CC arch-darwin-c-debug/obj/sys/info/ftn-custom/zverboseinfof.o
.
.
.
FC arch-darwin-c-debug/obj/snes/f90-mod/petscsnesmod.o
FC arch-darwin-c-debug/obj/ts/f90-mod/petsctsmod.o
FC arch-darwin-c-debug/obj/tao/f90-mod/petsctaomod.o
CLINKER arch-darwin-c-debug/lib/libpetsc.PETSC_MAJOR.PETSC_MINOR.PETSC_PATCH.dylib
DSYMUTIL arch-darwin-c-debug/lib/libpetsc.PETSC_MAJOR.PETSC_MINOR.PETSC_PATCH.dylib
gmake[2]: Leaving directory '/your/petsc/dir'
gmake[1]: Leaving directory '/your/petsc/dir'
=========================================
Running test examples to verify correct installation
Using PETSC_DIR=/your/petsc/dir and PETSC_ARCH=your-petsc-arch
C/C++ example src/snes/examples/tutorials/ex19 run successfully with 1 MPI process
C/C++ example src/snes/examples/tutorials/ex19 run successfully with 2 MPI processes
Fortran example src/snes/examples/tutorials/ex5f run successfully with 1 MPI process
Completed test examples
Congratulations!#
You now have a working PETSc installation and are ready to start using the library!
Footnotes
- 1
It is possible to configure PETSc using python2, however support for python2 will be discontinued in the future and so we recommend that users do not configure their PETSc installations using it.
- 2
Should you be missing any of these dependencies or would like to update them, either download and install the latest versions from their respective websites, or use your preferred package manager to update them. For example on macOS using the package manager homebrew to install python3
$ brew update
$ brew list # Show all packages installed through brew
$ brew upgrade # Update packages already installed through brew
$ brew install python3
- 3(1,2)
The BLAS/LAPACK package installed as part of this tutorial is a reference implementation and a suitable starting point to get PETSc running, but is generally not as performant as more optimized libraries. See the libaray guide for further details.