xref: /petsc/doc/install/multibuild.md (revision 9b92b1d3a7bbc5a081edc9021bfd15a36804dd1c)
1*9b92b1d3SBarry Smith(doc_multi)=
2*9b92b1d3SBarry Smith
3*9b92b1d3SBarry Smith# Maintaining Your PETSc Installation(s)
4*9b92b1d3SBarry Smith
5*9b92b1d3SBarry SmithSometimes it is useful to have multiple concurrently built versions of PETSc installed,
6*9b92b1d3SBarry Smithfor example you may have a `arch-darwin-opt` and `arch-darwin-debug`. This would allow
7*9b92b1d3SBarry Smithyou to run a highly optimized performance version of your code and a debug version simply
8*9b92b1d3SBarry Smithby changing the `$PETSC_ARCH` environment variable.
9*9b92b1d3SBarry Smith
10*9b92b1d3SBarry Smith## Environmental Variables `$PETSC_DIR` And `$PETSC_ARCH`
11*9b92b1d3SBarry Smith
12*9b92b1d3SBarry Smith:::{note}
13*9b92b1d3SBarry SmithApplications completely providing their own makefiles do not need to use `$PETSC_DIR`
14*9b92b1d3SBarry Smithor `$PETSC_ARCH`
15*9b92b1d3SBarry Smith
16*9b92b1d3SBarry Smith`$PETSC_ARCH` is only needed for in-place installations. For out-of-place
17*9b92b1d3SBarry Smithinstallations see {ref}`documentation <doc_config_install>`.
18*9b92b1d3SBarry Smith:::
19*9b92b1d3SBarry Smith
20*9b92b1d3SBarry Smith`$PETSC_DIR` and `$PETSC_ARCH` (in-place installs only) are used by the PETSc
21*9b92b1d3SBarry Smithmakefiles to indicate which directory and configuration of PETSc to use when compiling
22*9b92b1d3SBarry Smithexamples or application code. These variables can be set as environment variables or
23*9b92b1d3SBarry Smithspecified on the command line:
24*9b92b1d3SBarry Smith
25*9b92b1d3SBarry Smith- Specify environment variable for bash (can be specified in `~/.bashrc` or
26*9b92b1d3SBarry Smith  `~/.bash_profile`):
27*9b92b1d3SBarry Smith
28*9b92b1d3SBarry Smith  ```console
29*9b92b1d3SBarry Smith  $ export PETSC_DIR=/absolute/path/to/petsc
30*9b92b1d3SBarry Smith  $ export PETSC_ARCH=linux-gnu-c-debug
31*9b92b1d3SBarry Smith  ```
32*9b92b1d3SBarry Smith
33*9b92b1d3SBarry Smith- Specify environment variable for csh/tcsh (can be specified in `~/.cshrc`):
34*9b92b1d3SBarry Smith
35*9b92b1d3SBarry Smith  ```console
36*9b92b1d3SBarry Smith  $ setenv PETSC_DIR /absolute/path/to/petsc
37*9b92b1d3SBarry Smith  $ setenv PETSC_ARCH linux-gnu-c-debug
38*9b92b1d3SBarry Smith  ```
39*9b92b1d3SBarry Smith
40*9b92b1d3SBarry Smith- Specify variable on commandline (bash) to build an example in
41*9b92b1d3SBarry Smith  `$PETSC_DIR/src/ts/tutorials`:
42*9b92b1d3SBarry Smith
43*9b92b1d3SBarry Smith  ```console
44*9b92b1d3SBarry Smith  $ PETSC_ARCH=linux-gnu-c-debug make PETSC_DIR=/absolute/path/to/petsc ex1
45*9b92b1d3SBarry Smith  ```
46*9b92b1d3SBarry Smith
47*9b92b1d3SBarry Smith`$PETSC_DIR` should point to the location of the PETSc installation. For out-of-place
48*9b92b1d3SBarry Smithinstallations this is the `--prefix` location. For in-place installations it is the
49*9b92b1d3SBarry Smithdirectory where you ran `configure`.
50*9b92b1d3SBarry Smith
51*9b92b1d3SBarry Smith(doc_multi_confcache)=
52*9b92b1d3SBarry Smith
53*9b92b1d3SBarry Smith## Configure Caching
54*9b92b1d3SBarry Smith
55*9b92b1d3SBarry SmithThe first time you build PETSc, you must first run `configure` which (among other
56*9b92b1d3SBarry Smiththings) serves to identify key characteristics about the computing environment:
57*9b92b1d3SBarry Smith
58*9b92b1d3SBarry Smith- The type of operating system
59*9b92b1d3SBarry Smith- Available compilers, their locations, and versions
60*9b92b1d3SBarry Smith- Location of common system header-files
61*9b92b1d3SBarry Smith- Location of common system libraries
62*9b92b1d3SBarry Smith- Whether your system supports certain instruction types (e.g. AVX)
63*9b92b1d3SBarry Smith- And more...
64*9b92b1d3SBarry Smith
65*9b92b1d3SBarry SmithWhile many things that `configure` must check are liable to change in between
66*9b92b1d3SBarry Smithconsecutive `configure` invocations, some things are very unlikely -- if ever -- to
67*9b92b1d3SBarry Smithchange. Hence `configure` can safely cache and reuse these values in subsequent
68*9b92b1d3SBarry Smith`configure` runs, helping to speed up the lengthy process. A similar system is also used
69*9b92b1d3SBarry Smithwhen determining whether to rebuild various packages installed through PETSc.
70*9b92b1d3SBarry Smith
71*9b92b1d3SBarry Smith:::{note}
72*9b92b1d3SBarry SmithWhile the caching system used by `configure` is very useful, it usually errs on
73*9b92b1d3SBarry Smiththe side of caution. If a change has occurred in your system which could reasonably
74*9b92b1d3SBarry Smithchange how a package/program is compiled, `configure` will automatically rebuild this
75*9b92b1d3SBarry Smithsoftware for you.
76*9b92b1d3SBarry Smith
77*9b92b1d3SBarry SmithIf you would like to enforce that `configure` does not use any cached values, you may
78*9b92b1d3SBarry Smithuse the `--force` option when configuring your PETSc installation:
79*9b92b1d3SBarry Smith
80*9b92b1d3SBarry Smith```console
81*9b92b1d3SBarry Smith$ ./configure --some-args --force
82*9b92b1d3SBarry Smith```
83*9b92b1d3SBarry Smith
84*9b92b1d3SBarry SmithKeep in mind however that this will only disable `configure`'s cache, not any other
85*9b92b1d3SBarry Smithcaching mechanism potentially in use, such as [CCache](https://ccache.dev/).
86*9b92b1d3SBarry Smith:::
87*9b92b1d3SBarry Smith
88*9b92b1d3SBarry Smith:::{admonition} Caution
89*9b92b1d3SBarry Smith:class: yellow
90*9b92b1d3SBarry Smith
91*9b92b1d3SBarry SmithIf one still suspects malfeasance due to `configure` caching, or some corruption has
92*9b92b1d3SBarry Smithoccurred due to a faulty `configure` one may use the nuclear option
93*9b92b1d3SBarry Smith`--with-clean`. This will **permanently delete all build files, including installed
94*9b92b1d3SBarry Smithpackages** under `$PETSC_DIR/$PETSC_ARCH` (effectively a "clean slate") before
95*9b92b1d3SBarry Smithrunning `configure`. The only thing preserved during this process is the
96*9b92b1d3SBarry Smith`reconfigure` script:
97*9b92b1d3SBarry Smith
98*9b92b1d3SBarry Smith```console
99*9b92b1d3SBarry Smith$ ./configure --many-args --with-clean
100*9b92b1d3SBarry Smith```
101*9b92b1d3SBarry Smith:::
102*9b92b1d3SBarry Smith
103*9b92b1d3SBarry Smith## Reconfigure
104*9b92b1d3SBarry Smith
105*9b92b1d3SBarry SmithFor the reasons listed {ref}`above <doc_multi_confcache>`, the automatically generated
106*9b92b1d3SBarry Smith`$PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py` (henceforth referred
107*9b92b1d3SBarry Smithto simply as `reconfigure`) script is generated for you upon successfully finishing
108*9b92b1d3SBarry Smith`configure`. `reconfigure` is a short-hand way of repeating your original
109*9b92b1d3SBarry Smith`configure` invocation with the same arguments. In addition, `reconfigure` will also
110*9b92b1d3SBarry Smithalways explicitly define `PETSC_ARCH` within the `configure` arguments, so there is no
111*9b92b1d3SBarry Smithneed to specify which PETSc installation you wish to reconfigure.
112*9b92b1d3SBarry Smith
113*9b92b1d3SBarry SmithFor example running the following `configure`:
114*9b92b1d3SBarry Smith
115*9b92b1d3SBarry Smith```console
116*9b92b1d3SBarry Smith$ ./configure --download-mpich --download-fblaslapack --with-debugging=1
117*9b92b1d3SBarry Smith```
118*9b92b1d3SBarry Smith
119*9b92b1d3SBarry SmithWill result in the following `reconfigure`:
120*9b92b1d3SBarry Smith
121*9b92b1d3SBarry Smith```python
122*9b92b1d3SBarry Smith#!/usr/local/opt/python@3.9/bin/python3.9
123*9b92b1d3SBarry Smithif __name__ == '__main__':
124*9b92b1d3SBarry Smith  import sys
125*9b92b1d3SBarry Smith  import os
126*9b92b1d3SBarry Smith  sys.path.insert(0, os.path.abspath('config'))
127*9b92b1d3SBarry Smith  import configure
128*9b92b1d3SBarry Smith  configure_options = [
129*9b92b1d3SBarry Smith    '--download-mpich',
130*9b92b1d3SBarry Smith    '--download-fblaslapack',
131*9b92b1d3SBarry Smith    '--with-debugging=1',
132*9b92b1d3SBarry Smith    'PETSC_ARCH=arch-darwin-c-debug',
133*9b92b1d3SBarry Smith  ]
134*9b92b1d3SBarry Smith  configure.petsc_configure(configure_options)
135*9b92b1d3SBarry Smith```
136*9b92b1d3SBarry Smith
137*9b92b1d3SBarry SmithIn order to rerun this `configure` with the same arguments simply do:
138*9b92b1d3SBarry Smith
139*9b92b1d3SBarry Smith```console
140*9b92b1d3SBarry Smith$ $PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py
141*9b92b1d3SBarry Smith```
142*9b92b1d3SBarry Smith
143*9b92b1d3SBarry Smith:::{Note}
144*9b92b1d3SBarry SmithThe `reconfigure` script also comes with one additional powerful tool, namely the
145*9b92b1d3SBarry Smithability to additively set new `configure` options, and also to change the values of
146*9b92b1d3SBarry Smithprevious `configure` options! This is particularly useful if one has a lot of
147*9b92b1d3SBarry Smith{ref}`external packages <doc_externalsoftware>` installed through PETSc and would like
148*9b92b1d3SBarry Smithto install another.
149*9b92b1d3SBarry Smith
150*9b92b1d3SBarry SmithOne need only call `reconfigure`, supplying any additional command-line arguments as
151*9b92b1d3SBarry Smithif it were the regular `configure`. Suppose one had an installation of PETSc with the following arguments (represented in the `reconfigure` script):
152*9b92b1d3SBarry Smith
153*9b92b1d3SBarry Smith```python
154*9b92b1d3SBarry Smith#!/usr/local/opt/python@3.9/bin/python3.9
155*9b92b1d3SBarry Smithif __name__ == '__main__':
156*9b92b1d3SBarry Smith  import sys
157*9b92b1d3SBarry Smith  import os
158*9b92b1d3SBarry Smith  sys.path.insert(0, os.path.abspath('config'))
159*9b92b1d3SBarry Smith  import configure
160*9b92b1d3SBarry Smith  configure_options = [
161*9b92b1d3SBarry Smith    '--download-mpich',
162*9b92b1d3SBarry Smith    '--download-fblaslapack',
163*9b92b1d3SBarry Smith    '--with-debugging=1',
164*9b92b1d3SBarry Smith    'PETSC_ARCH=arch-darwin-c-debug',
165*9b92b1d3SBarry Smith  ]
166*9b92b1d3SBarry Smith  configure.petsc_configure(configure_options)
167*9b92b1d3SBarry Smith```
168*9b92b1d3SBarry Smith
169*9b92b1d3SBarry SmithThen calling it with new arguments:
170*9b92b1d3SBarry Smith
171*9b92b1d3SBarry Smith```console
172*9b92b1d3SBarry Smith$ $PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py --download-zlib
173*9b92b1d3SBarry Smith```
174*9b92b1d3SBarry Smith
175*9b92b1d3SBarry SmithWill install [zlib](https://zlib.net/) into that `reconfigure`'s home
176*9b92b1d3SBarry Smith`$PETSC_ARCH`.
177*9b92b1d3SBarry Smith:::
178*9b92b1d3SBarry Smith
179*9b92b1d3SBarry SmithWhile it is automatically done for you the first time you `configure` and build PETSc,
180*9b92b1d3SBarry Smithit is useful to symlink the `reconfigure` script for each `$PETSC_ARCH` that you
181*9b92b1d3SBarry Smithintend to rebuild often into your `$PETSC_DIR`:
182*9b92b1d3SBarry Smith
183*9b92b1d3SBarry Smith```console
184*9b92b1d3SBarry Smith$ ln -s $PETSC_DIR/$PETSC_ARCH/lib/petsc/conf/reconfigure-$PETSC_ARCH.py $PETSC_DIR/
185*9b92b1d3SBarry Smith```
186*9b92b1d3SBarry Smith
187*9b92b1d3SBarry Smith## Updating or Reinstalling PETSc
188*9b92b1d3SBarry Smith
189*9b92b1d3SBarry SmithIf you follow the main or release branches of PETSc you can update your libraries with:
190*9b92b1d3SBarry Smith
191*9b92b1d3SBarry Smith```console
192*9b92b1d3SBarry Smith$ git pull
193*9b92b1d3SBarry Smith$ make libs
194*9b92b1d3SBarry Smith```
195*9b92b1d3SBarry Smith
196*9b92b1d3SBarry SmithMost of the time this will work, if there are errors regarding compiling Fortran stubs you
197*9b92b1d3SBarry Smithneed to also do:
198*9b92b1d3SBarry Smith
199*9b92b1d3SBarry Smith```console
200*9b92b1d3SBarry Smith$ make allfortranstubs
201*9b92b1d3SBarry Smith```
202