xref: /petsc/doc/install/install_tutorial.md (revision f8b9f887efa5534f423807e37a1fe2e87d779bac)
1(tut_install)=
2
3# Quick Start Tutorial
4
5## QQTW (Quickest Quick-start in The West)
6
7On systems where MPI and [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html)
8are installed, {ref}`download <doc_download>` PETSc and build with:
9
10```console
11$ ./configure
12$ make all check
13```
14
15Or to specify compilers and have PETSc download and install [MPICH](https://www.mpich.org/) and [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html) [^blas] (when they are not already on
16your machine):
17
18```console
19$ ./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack
20$ make all check
21```
22
23Don't need Fortran? Use `--with-fortran-bindings=0` to reduce the build times. If you
24are not using {ref}`external packages <doc_externalsoftware>` that use Fortran (for
25example, [MUMPS](https://mumps-solver.org/) requires Fortran) you can use
26`--with-fc=0` for even faster build times.
27
28:::{admonition} Encounter problems?
291. Read the error message from `configure`!
302. Read help `./configure --help`.
313. Refer to {ref}`configuration faq <doc_config_faq>` (e.g. build PETSc without a
32   Fortran compiler).
334. `make` problems? Just copy/paste `make` command printed by the `configure`
34
35   : footer including any `$PETSC_DIR` and `$PETSC_ARCH` options. It may look
36     similar to:
37   ```
38   xxx=========================================================================xxx
39   Configure stage complete. Now build PETSc libraries with:
40   make PETSC_DIR=/Users/jacobfaibussowitsch/NoSync/petsc PETSC_ARCH=arch-darwin-c-debug all
41   xxx=========================================================================xxx
42   ```
435. Check the {ref}`bug-reporting <doc_creepycrawly>` section.
44:::
45
46______________________________________________________________________
47
48(tut_install_prereq)=
49
50## Prerequisites
51
52:::{important}
53This tutorial assumes basic knowledge on the part of the user on how to
54navigate your system using the Command-Line Interface (CLI), a.k.a. "from the
55terminal". Being a programmable solver suite, PETSc does not have a
56front-end Graphical User Interface, so any and all tutorial examples here will
57almost exclusively use the terminal.
58
59While this tutorial will provide all commands necessary, it will not explain the usage
60or syntax of commands not directly implemented by PETSc. If you are unfamiliar with the
61command line, or would like to refresh your understanding, consider reviewing tutorials
62on basic [Unix](https://www.tutorialspoint.com/unix/index.htm) and [shell](https://www.tutorialspoint.com/unix/shell_scripting.htm) usage.
63:::
64
65Before beginning, make sure you have the following pre-requisites installed and up to
66date:
67
68- [make](https://www.gnu.org/software/make/)
69- [python3](https://www.python.org/) [^id5]
70- C Compiler (e.g. [gcc](https://gcc.gnu.org/) or [clang](https://clang.llvm.org/))
71- [OPTIONAL] Fortran Compiler (e.g. [gfortran](https://gcc.gnu.org/wiki/GFortran))
72- [OPTIONAL] [git](https://git-scm.com/)
73
74It is important to make sure that your compilers are correctly installed [^id6] (i.e. functional
75and in your `$PATH`). To test the compilers, run the following commands:
76
77```console
78$ printf '#include<stdio.h>\nint main(){printf("cc OK!\\n");}' > t.c && cc t.c && ./a.out && rm -f t.c a.out
79```
80
81:::{note}
82While it is recommended that you have functional C++ and Fortran compilers installed,
83they are not directly required to run PETSc in its default state. If they are
84functioning, PETSc will automatically find them during the configure stage, however it
85is always useful to test them on your own.
86
87```console
88$ printf '#include<iostream>\nint main(){std::cout<<"c++ OK!"<<std::endl;}' > t.cpp && c++ t.cpp && ./a.out && rm -f t.cpp a.out
89$ printf 'program t\nprint"(a)","gfortran OK!"\nend program' > t.f90 && gfortran t.f90 && ./a.out && rm -f t.f90 a.out
90```
91:::
92
93If compilers are working, each command should print out `<compiler_name> OK!` on the command
94line.
95
96(tut_install_download)=
97
98## Downloading Source
99
100See the {ref}`download documentation <doc_download>` for additional details.
101
102With all dependencies installed, navigate to a suitable directory on your machine and pull
103the latest version of the PETSc library to your machine with git. The following commands
104will create a directory "petsc" inside the current directory and retrieve the latest
105release branch of the repository.
106
107```console
108$ mkdir ~/projects
109$ cd ~/projects
110$ git clone -b release https://gitlab.com/petsc/petsc
111$ cd petsc
112```
113
114:::{note}
115If git is not available - or if pre-generated Fortran stubs are required (i.e avoid download and
116install of sowing package - that also requires a C++ compiler) one can download a release tarball.
117See {ref}`download documentation <doc_download>` for additional details.
118:::
119
120:::{Warning}
121It is **IMPERATIVE** to install PETSc in a directory whose path does not contain any of
122the following special characters:
123
124\~ ! @ # \$ % ^ & * ( ) \` ; < > ? , [ ] { } ' " | (including spaces!)
125
126While PETSc is equipped to handle these errors, other installed dependencies may not be
127so well protected.
128:::
129
130The download process may take a few minutes to complete. Successfully running this command
131should yield a similar output:
132
133```console
134$ git clone -b release https://gitlab.com/petsc/petsc.git petsc
135Cloning into 'petsc'...
136remote: Enumerating objects: 862597, done.
137remote: Counting objects: 100% (862597/862597), done.
138remote: Compressing objects: 100% (197622/197622), done.
139remote: Total 862597 (delta 660708), reused 862285 (delta 660444)
140Receiving objects: 100% (862597/862597), 205.11 MiB | 3.17 MiB/s, done.
141Resolving deltas: 100% (660708/660708), done.
142Updating files: 100% (7748/7748), done.
143$ cd petsc
144$ git pull # Not strictly necessary, but nice to check
145Already up to date.
146```
147
148(tut_install_config)=
149
150## Configuration
151
152See {ref}`install documentation <doc_config_faq>` for more details.
153
154Next, PETSc needs to be configured using `configure` for your system with your
155specific options. This is the stage where users can specify the exact parameters to
156customize their PETSc installation. Common configuration options are:
157
158- {ref}`Specifying different compilers. <doc_config_compilers>`
159- {ref}`Specifying different MPI implementations. <doc_config_mpi>`
160- Enabling [CUDA](https://developer.nvidia.com/cuda-toolkit)/[OpenCL](https://www.khronos.org/opencl/)/[ViennaCL](http://viennacl.sourceforge.net/)
161  {ref}`support. <doc_config_accel>`
162- {ref}`Specifying options <doc_config_blaslapack>` for [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html).
163- {ref}`Specifying external packages <doc_config_externalpack>` to use or download
164  automatically. PETSc can automatically download and install a wide range of other
165  supporting software.
166- Setting various known machine quantities for PETSc to use such as known integral sizes,
167  memory alignment, or additional compiler flags.
168
169:::{important}
170You MUST specify all of your configuration options at this stage. In order to enable
171additional options or packages in the future, you will have to reconfigure your PETSc
172installation in a similar manner with these options enabled.
173
174For a full list of available options call
175
176```console
177$ ./configure --help
178```
179:::
180
181All PETSc options and flags follow the standard CLI formats `--option-string=<value>` or
182`--option-string`, where `<value>` is typically either `1` (for true) or `0` (for
183false) or a directory path. Directory paths must be absolute (i.e. full path from the root
184directory of your machine), but do accept environment variables as input.
185
186From `$PETSC_DIR` call the following `configure` command to configure PETSc as well
187as download and install [MPICH](https://www.mpich.org/) and a [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html) [^blas] [reference implementation](https://bitbucket.org/petsc/pkg-fblaslapack/src/master/) on your system.
188
189```console
190$ ./configure --download-mpich --download-fblaslapack
191```
192
193PETSc will begin configuring and printing its progress. A successful `configure` will
194have the following general structure as its output:
195
196```text
197===============================================================================
198          Configuring PETSc to compile on your system
199===============================================================================
200TESTING: configureSomething from PETSc.something(config/PETSc/configurescript.py:lineNUM)
201===============================================================================
202          Trying to download MPICH_DOWNLOAD_URL for MPICH
203===============================================================================
204===============================================================================
205          Running configure on MPICH; this may take several minutes
206===============================================================================
207===============================================================================
208          Running make on MPICH; this may take several minutes
209===============================================================================
210===============================================================================
211          Running make install on MPICH; this may take several minutes
212===============================================================================
213===============================================================================
214          Trying to download FBLASLAPACK_URL for FBLASLAPACK
215===============================================================================
216===============================================================================
217          Compiling FBLASLAPACK; this may take several minutes
218===============================================================================
219===============================================================================
220          Trying to download SOWING_DOWNLOAD_URL for SOWING
221===============================================================================
222===============================================================================
223          Running configure on SOWING; this may take several minutes
224===============================================================================
225===============================================================================
226          Running make on SOWING; this may take several minutes
227===============================================================================
228===============================================================================
229          Running make install on SOWING; this may take several minutes
230===============================================================================
231Compilers:
232  C Compiler:   Location information and flags
233  C++ Compiler: Location information and flags
234.
235.
236.
237MPI:
238     Includes: Include path
239Other Installed Packages:
240.
241.
242.
243PETSc:
244     PETSC_ARCH: {YOUR_PETSC_ARCH}
245     PETSC_DIR:  {YOUR_PETSC_DIR}
246.
247.
248.
249.
250
251xxx=========================================================================xxx
252Configure stage complete. Now build PETSc libraries with (gnumake build):
253make PETSC_DIR=/your/petsc/dir PETSC_ARCH=your-petsc-arch all
254xxx=========================================================================xxx
255```
256
257(tut_install_compile)=
258
259## Compilation
260
261After successfully configuring, build the binaries from source using the `make`
262command. This stage may take a few minutes, and will consume a great deal of system
263resources as the PETSc is compiled in parallel.
264
265```console
266$ make all check
267```
268
269A successful `make` will provide an output of the following structure:
270
271```text
272-----------------------------------------
273PETSC_VERSION_RELEASE
274.
275.
276.
277-----------------------------------------
278#define SOME_PETSC_VARIABLE
279.
280.
281.
282-----------------------------------------
283Installed Compiler, Package, and Library Information
284.
285.
286.
287=========================================
288       FC arch-darwin-c-debug/obj/src/sys/ftn-mod/petscsysmod.o
289       FC arch-darwin-c-debug/obj/src/sys/fsrc/somefort.o
290       .
291       .
292       .
293       FC arch-darwin-c-debug/obj/src/snes/ftn-mod/petscsnesmod.o
294       FC arch-darwin-c-debug/obj/src/ts/ftn-mod/petsctsmod.o
295       FC arch-darwin-c-debug/obj/src/tao/ftn-mod/petsctaomod.o
296  CLINKER arch-darwin-c-debug/lib/libpetsc.PETSC_MAJOR.PETSC_MINOR.PETSC_PATCH.dylib
297 DSYMUTIL arch-darwin-c-debug/lib/libpetsc.PETSC_MAJOR.PETSC_MINOR.PETSC_PATCH.dylib
298gmake[2]: Leaving directory '/your/petsc/dir'
299gmake[1]: Leaving directory '/your/petsc/dir'
300=========================================
301Running test examples to verify correct installation
302Using PETSC_DIR=/your/petsc/dir and PETSC_ARCH=your-petsc-arch
303C/C++ example src/snes/examples/tutorials/ex19 run successfully with 1 MPI process
304C/C++ example src/snes/examples/tutorials/ex19 run successfully with 2 MPI processes
305Fortran example src/snes/examples/tutorials/ex5f run successfully with 1 MPI process
306Completed test examples
307```
308
309(tut_install_fin)=
310
311## Congratulations!
312
313You now have a working PETSc installation and are ready to start using the library!
314
315```{rubric} Footnotes
316```
317
318[^id5]: python2 is no longer supported.
319
320[^id6]: Should you be missing any of these dependencies or would like to update them, either
321    download and install the latest versions from their respective websites, or use your
322    preferred package manager to update them. For example, for macOS see {any}`doc_macos_install`
323
324[^blas]: The [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html) package
325    installed as part of this tutorial is a [reference implementation](https://bitbucket.org/petsc/pkg-fblaslapack/src/master/) and a suitable starting
326    point to get PETSc running, but is generally not as performant as more optimized
327    libraries. See the {ref}`libaray guide <ch_blas_lapack_avail_libs>` for further
328    details.
329