19b92b1d3SBarry Smith(doc_multi)= 29b92b1d3SBarry Smith 39b92b1d3SBarry Smith# Maintaining Your PETSc Installation(s) 49b92b1d3SBarry Smith 59b92b1d3SBarry SmithSometimes it is useful to have multiple concurrently built versions of PETSc installed, 69b92b1d3SBarry Smithfor example you may have a `arch-darwin-opt` and `arch-darwin-debug`. This would allow 79b92b1d3SBarry Smithyou to run a highly optimized performance version of your code and a debug version simply 89b92b1d3SBarry Smithby changing the `$PETSC_ARCH` environment variable. 99b92b1d3SBarry Smith 109b92b1d3SBarry Smith## Environmental Variables `$PETSC_DIR` And `$PETSC_ARCH` 119b92b1d3SBarry Smith 129b92b1d3SBarry Smith:::{note} 139b92b1d3SBarry SmithApplications completely providing their own makefiles do not need to use `$PETSC_DIR` 149b92b1d3SBarry Smithor `$PETSC_ARCH` 159b92b1d3SBarry Smith 169b92b1d3SBarry Smith`$PETSC_ARCH` is only needed for in-place installations. For out-of-place 179b92b1d3SBarry Smithinstallations see {ref}`documentation <doc_config_install>`. 189b92b1d3SBarry Smith::: 199b92b1d3SBarry Smith 209b92b1d3SBarry Smith`$PETSC_DIR` and `$PETSC_ARCH` (in-place installs only) are used by the PETSc 219b92b1d3SBarry Smithmakefiles to indicate which directory and configuration of PETSc to use when compiling 229b92b1d3SBarry Smithexamples or application code. These variables can be set as environment variables or 239b92b1d3SBarry Smithspecified on the command line: 249b92b1d3SBarry Smith 259b92b1d3SBarry Smith- Specify environment variable for bash (can be specified in `~/.bashrc` or 269b92b1d3SBarry Smith `~/.bash_profile`): 279b92b1d3SBarry Smith 289b92b1d3SBarry Smith ```console 299b92b1d3SBarry Smith $ export PETSC_DIR=/absolute/path/to/petsc 309b92b1d3SBarry Smith $ export PETSC_ARCH=linux-gnu-c-debug 319b92b1d3SBarry Smith ``` 329b92b1d3SBarry Smith 339b92b1d3SBarry Smith- Specify environment variable for csh/tcsh (can be specified in `~/.cshrc`): 349b92b1d3SBarry Smith 359b92b1d3SBarry Smith ```console 369b92b1d3SBarry Smith $ setenv PETSC_DIR /absolute/path/to/petsc 379b92b1d3SBarry Smith $ setenv PETSC_ARCH linux-gnu-c-debug 389b92b1d3SBarry Smith ``` 399b92b1d3SBarry Smith 409b92b1d3SBarry Smith- Specify variable on commandline (bash) to build an example in 419b92b1d3SBarry Smith `$PETSC_DIR/src/ts/tutorials`: 429b92b1d3SBarry Smith 439b92b1d3SBarry Smith ```console 449b92b1d3SBarry Smith $ PETSC_ARCH=linux-gnu-c-debug make PETSC_DIR=/absolute/path/to/petsc ex1 459b92b1d3SBarry Smith ``` 469b92b1d3SBarry Smith 479b92b1d3SBarry Smith`$PETSC_DIR` should point to the location of the PETSc installation. For out-of-place 489b92b1d3SBarry Smithinstallations this is the `--prefix` location. For in-place installations it is the 499b92b1d3SBarry Smithdirectory where you ran `configure`. 509b92b1d3SBarry Smith 519b92b1d3SBarry Smith(doc_multi_confcache)= 529b92b1d3SBarry Smith 539b92b1d3SBarry Smith## Configure Caching 549b92b1d3SBarry Smith 559b92b1d3SBarry SmithThe first time you build PETSc, you must first run `configure` which (among other 569b92b1d3SBarry Smiththings) serves to identify key characteristics about the computing environment: 579b92b1d3SBarry Smith 589b92b1d3SBarry Smith- The type of operating system 599b92b1d3SBarry Smith- Available compilers, their locations, and versions 609b92b1d3SBarry Smith- Location of common system header-files 619b92b1d3SBarry Smith- Location of common system libraries 629b92b1d3SBarry Smith- Whether your system supports certain instruction types (e.g. AVX) 639b92b1d3SBarry Smith- And more... 649b92b1d3SBarry Smith 659b92b1d3SBarry SmithWhile many things that `configure` must check are liable to change in between 669b92b1d3SBarry Smithconsecutive `configure` invocations, some things are very unlikely -- if ever -- to 679b92b1d3SBarry Smithchange. Hence `configure` can safely cache and reuse these values in subsequent 689b92b1d3SBarry Smith`configure` runs, helping to speed up the lengthy process. A similar system is also used 699b92b1d3SBarry Smithwhen determining whether to rebuild various packages installed through PETSc. 709b92b1d3SBarry Smith 719b92b1d3SBarry Smith:::{note} 729b92b1d3SBarry SmithWhile the caching system used by `configure` is very useful, it usually errs on 739b92b1d3SBarry Smiththe side of caution. If a change has occurred in your system which could reasonably 749b92b1d3SBarry Smithchange how a package/program is compiled, `configure` will automatically rebuild this 759b92b1d3SBarry Smithsoftware for you. 769b92b1d3SBarry Smith 779b92b1d3SBarry SmithIf you would like to enforce that `configure` does not use any cached values, you may 789b92b1d3SBarry Smithuse the `--force` option when configuring your PETSc installation: 799b92b1d3SBarry Smith 809b92b1d3SBarry Smith```console 819b92b1d3SBarry Smith$ ./configure --some-args --force 829b92b1d3SBarry Smith``` 839b92b1d3SBarry Smith 849b92b1d3SBarry SmithKeep in mind however that this will only disable `configure`'s cache, not any other 859b92b1d3SBarry Smithcaching mechanism potentially in use, such as [CCache](https://ccache.dev/). 869b92b1d3SBarry Smith::: 879b92b1d3SBarry Smith 889b92b1d3SBarry Smith:::{admonition} Caution 899b92b1d3SBarry Smith:class: yellow 909b92b1d3SBarry Smith 919b92b1d3SBarry SmithIf one still suspects malfeasance due to `configure` caching, or some corruption has 929b92b1d3SBarry Smithoccurred due to a faulty `configure` one may use the nuclear option 939b92b1d3SBarry Smith`--with-clean`. This will **permanently delete all build files, including installed 949b92b1d3SBarry Smithpackages** under `$PETSC_DIR/$PETSC_ARCH` (effectively a "clean slate") before 959b92b1d3SBarry Smithrunning `configure`. The only thing preserved during this process is the 969b92b1d3SBarry Smith`reconfigure` script: 979b92b1d3SBarry Smith 989b92b1d3SBarry Smith```console 999b92b1d3SBarry Smith$ ./configure --many-args --with-clean 1009b92b1d3SBarry Smith``` 1019b92b1d3SBarry Smith::: 1029b92b1d3SBarry Smith 1039b92b1d3SBarry Smith## Reconfigure 1049b92b1d3SBarry Smith 1059b92b1d3SBarry SmithFor the reasons listed {ref}`above <doc_multi_confcache>`, the automatically generated 1069b92b1d3SBarry Smith`$PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py` (henceforth referred 1079b92b1d3SBarry Smithto simply as `reconfigure`) script is generated for you upon successfully finishing 1089b92b1d3SBarry Smith`configure`. `reconfigure` is a short-hand way of repeating your original 1099b92b1d3SBarry Smith`configure` invocation with the same arguments. In addition, `reconfigure` will also 1109b92b1d3SBarry Smithalways explicitly define `PETSC_ARCH` within the `configure` arguments, so there is no 1119b92b1d3SBarry Smithneed to specify which PETSc installation you wish to reconfigure. 1129b92b1d3SBarry Smith 1139b92b1d3SBarry SmithFor example running the following `configure`: 1149b92b1d3SBarry Smith 1159b92b1d3SBarry Smith```console 1169b92b1d3SBarry Smith$ ./configure --download-mpich --download-fblaslapack --with-debugging=1 1179b92b1d3SBarry Smith``` 1189b92b1d3SBarry Smith 1199b92b1d3SBarry SmithWill result in the following `reconfigure`: 1209b92b1d3SBarry Smith 1219b92b1d3SBarry Smith```python 1229b92b1d3SBarry Smith#!/usr/local/opt/python@3.9/bin/python3.9 1239b92b1d3SBarry Smithif __name__ == '__main__': 1249b92b1d3SBarry Smith import sys 1259b92b1d3SBarry Smith import os 1269b92b1d3SBarry Smith sys.path.insert(0, os.path.abspath('config')) 1279b92b1d3SBarry Smith import configure 1289b92b1d3SBarry Smith configure_options = [ 1299b92b1d3SBarry Smith '--download-mpich', 1309b92b1d3SBarry Smith '--download-fblaslapack', 1319b92b1d3SBarry Smith '--with-debugging=1', 1329b92b1d3SBarry Smith 'PETSC_ARCH=arch-darwin-c-debug', 1339b92b1d3SBarry Smith ] 1349b92b1d3SBarry Smith configure.petsc_configure(configure_options) 1359b92b1d3SBarry Smith``` 1369b92b1d3SBarry Smith 1379b92b1d3SBarry SmithIn order to rerun this `configure` with the same arguments simply do: 1389b92b1d3SBarry Smith 1399b92b1d3SBarry Smith```console 1409b92b1d3SBarry Smith$ $PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py 1419b92b1d3SBarry Smith``` 1429b92b1d3SBarry Smith 1439b92b1d3SBarry Smith:::{Note} 1449b92b1d3SBarry SmithThe `reconfigure` script also comes with one additional powerful tool, namely the 1459b92b1d3SBarry Smithability to additively set new `configure` options, and also to change the values of 1469b92b1d3SBarry Smithprevious `configure` options! This is particularly useful if one has a lot of 1479b92b1d3SBarry Smith{ref}`external packages <doc_externalsoftware>` installed through PETSc and would like 1489b92b1d3SBarry Smithto install another. 1499b92b1d3SBarry Smith 1509b92b1d3SBarry SmithOne need only call `reconfigure`, supplying any additional command-line arguments as 1519b92b1d3SBarry Smithif it were the regular `configure`. Suppose one had an installation of PETSc with the following arguments (represented in the `reconfigure` script): 1529b92b1d3SBarry Smith 1539b92b1d3SBarry Smith```python 1549b92b1d3SBarry Smith#!/usr/local/opt/python@3.9/bin/python3.9 1559b92b1d3SBarry Smithif __name__ == '__main__': 1569b92b1d3SBarry Smith import sys 1579b92b1d3SBarry Smith import os 1589b92b1d3SBarry Smith sys.path.insert(0, os.path.abspath('config')) 1599b92b1d3SBarry Smith import configure 1609b92b1d3SBarry Smith configure_options = [ 1619b92b1d3SBarry Smith '--download-mpich', 1629b92b1d3SBarry Smith '--download-fblaslapack', 1639b92b1d3SBarry Smith '--with-debugging=1', 1649b92b1d3SBarry Smith 'PETSC_ARCH=arch-darwin-c-debug', 1659b92b1d3SBarry Smith ] 1669b92b1d3SBarry Smith configure.petsc_configure(configure_options) 1679b92b1d3SBarry Smith``` 1689b92b1d3SBarry Smith 1699b92b1d3SBarry SmithThen calling it with new arguments: 1709b92b1d3SBarry Smith 1719b92b1d3SBarry Smith```console 1729b92b1d3SBarry Smith$ $PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py --download-zlib 1739b92b1d3SBarry Smith``` 1749b92b1d3SBarry Smith 1759b92b1d3SBarry SmithWill install [zlib](https://zlib.net/) into that `reconfigure`'s home 1769b92b1d3SBarry Smith`$PETSC_ARCH`. 1779b92b1d3SBarry Smith::: 1789b92b1d3SBarry Smith 1799b92b1d3SBarry SmithWhile it is automatically done for you the first time you `configure` and build PETSc, 1809b92b1d3SBarry Smithit is useful to symlink the `reconfigure` script for each `$PETSC_ARCH` that you 1819b92b1d3SBarry Smithintend to rebuild often into your `$PETSC_DIR`: 1829b92b1d3SBarry Smith 1839b92b1d3SBarry Smith```console 1849b92b1d3SBarry Smith$ ln -s $PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py $PETSC_DIR/ 1859b92b1d3SBarry Smith``` 1869b92b1d3SBarry Smith 1879b92b1d3SBarry Smith## Updating or Reinstalling PETSc 1889b92b1d3SBarry Smith 1899b92b1d3SBarry SmithIf you follow the main or release branches of PETSc you can update your libraries with: 1909b92b1d3SBarry Smith 1919b92b1d3SBarry Smith```console 1929b92b1d3SBarry Smith$ git pull 1939b92b1d3SBarry Smith$ make libs 1949b92b1d3SBarry Smith``` 1959b92b1d3SBarry Smith 1969b92b1d3SBarry SmithMost of the time this will work, if there are errors regarding compiling Fortran stubs you 1979b92b1d3SBarry Smithneed to also do: 1989b92b1d3SBarry Smith 1999b92b1d3SBarry Smith```console 200*649db6d2SBarry Smith$ make fortranbindings 2019b92b1d3SBarry Smith``` 202