19b92b1d3SBarry Smith(tut_install)= 29b92b1d3SBarry Smith 39b92b1d3SBarry Smith# Quick Start Tutorial 49b92b1d3SBarry Smith 59b92b1d3SBarry Smith## QQTW (Quickest Quick-start in The West) 69b92b1d3SBarry Smith 79b92b1d3SBarry SmithOn systems where MPI and [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html) 89b92b1d3SBarry Smithare installed, {ref}`download <doc_download>` PETSc and build with: 99b92b1d3SBarry Smith 109b92b1d3SBarry Smith```console 119b92b1d3SBarry Smith$ ./configure 129b92b1d3SBarry Smith$ make all check 139b92b1d3SBarry Smith``` 149b92b1d3SBarry Smith 159b92b1d3SBarry SmithOr 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 169b92b1d3SBarry Smithyour machine): 179b92b1d3SBarry Smith 189b92b1d3SBarry Smith```console 199b92b1d3SBarry Smith$ ./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack 209b92b1d3SBarry Smith$ make all check 219b92b1d3SBarry Smith``` 229b92b1d3SBarry Smith 239b92b1d3SBarry SmithDon't need Fortran? Use `--with-fortran-bindings=0` to reduce the build times. If you 249b92b1d3SBarry Smithare not using {ref}`external packages <doc_externalsoftware>` that use Fortran (for 259b92b1d3SBarry Smithexample, [MUMPS](https://mumps-solver.org/) requires Fortran) you can use 269b92b1d3SBarry Smith`--with-fc=0` for even faster build times. 279b92b1d3SBarry Smith 289b92b1d3SBarry Smith:::{admonition} Encounter problems? 299b92b1d3SBarry Smith1. Read the error message from `configure`! 309b92b1d3SBarry Smith2. Read help `./configure --help`. 319b92b1d3SBarry Smith3. Refer to {ref}`configuration faq <doc_config_faq>` (e.g. build PETSc without a 329b92b1d3SBarry Smith Fortran compiler). 339b92b1d3SBarry Smith4. `make` problems? Just copy/paste `make` command printed by the `configure` 349b92b1d3SBarry Smith 359b92b1d3SBarry Smith : footer including any `$PETSC_DIR` and `$PETSC_ARCH` options. It may look 369b92b1d3SBarry Smith similar to: 379b92b1d3SBarry Smith ``` 389b92b1d3SBarry Smith xxx=========================================================================xxx 399b92b1d3SBarry Smith Configure stage complete. Now build PETSc libraries with: 409b92b1d3SBarry Smith make PETSC_DIR=/Users/jacobfaibussowitsch/NoSync/petsc PETSC_ARCH=arch-darwin-c-debug all 419b92b1d3SBarry Smith xxx=========================================================================xxx 429b92b1d3SBarry Smith ``` 439b92b1d3SBarry Smith5. Check the {ref}`bug-reporting <doc_creepycrawly>` section. 449b92b1d3SBarry Smith::: 459b92b1d3SBarry Smith 469b92b1d3SBarry Smith______________________________________________________________________ 479b92b1d3SBarry Smith 489b92b1d3SBarry Smith(tut_install_prereq)= 499b92b1d3SBarry Smith 509b92b1d3SBarry Smith## Prerequisites 519b92b1d3SBarry Smith 529b92b1d3SBarry Smith:::{important} 539b92b1d3SBarry SmithThis tutorial assumes basic knowledge on the part of the user on how to 549b92b1d3SBarry Smithnavigate your system using the Command-Line Interface (CLI), a.k.a. "from the 559b92b1d3SBarry Smithterminal". Being a programmable solver suite, PETSc does not have a 569b92b1d3SBarry Smithfront-end Graphical User Interface, so any and all tutorial examples here will 579b92b1d3SBarry Smithalmost exclusively use the terminal. 589b92b1d3SBarry Smith 599b92b1d3SBarry SmithWhile this tutorial will provide all commands necessary, it will not explain the usage 609b92b1d3SBarry Smithor syntax of commands not directly implemented by PETSc. If you are unfamiliar with the 619b92b1d3SBarry Smithcommand line, or would like to refresh your understanding, consider reviewing tutorials 629b92b1d3SBarry Smithon basic [Unix](https://www.tutorialspoint.com/unix/index.htm) and [shell](https://www.tutorialspoint.com/unix/shell_scripting.htm) usage. 639b92b1d3SBarry Smith::: 649b92b1d3SBarry Smith 659b92b1d3SBarry SmithBefore beginning, make sure you have the following pre-requisites installed and up to 669b92b1d3SBarry Smithdate: 679b92b1d3SBarry Smith 689b92b1d3SBarry Smith- [make](https://www.gnu.org/software/make/) 699b92b1d3SBarry Smith- [python3](https://www.python.org/) [^id5] 709b92b1d3SBarry Smith- C Compiler (e.g. [gcc](https://gcc.gnu.org/) or [clang](https://clang.llvm.org/)) 719b92b1d3SBarry Smith- [OPTIONAL] Fortran Compiler (e.g. [gfortran](https://gcc.gnu.org/wiki/GFortran)) 729b92b1d3SBarry Smith- [OPTIONAL] [git](https://git-scm.com/) 739b92b1d3SBarry Smith 749b92b1d3SBarry SmithIt is important to make sure that your compilers are correctly installed [^id6] (i.e. functional 759b92b1d3SBarry Smithand in your `$PATH`). To test the compilers, run the following commands: 769b92b1d3SBarry Smith 779b92b1d3SBarry Smith```console 789b92b1d3SBarry Smith$ printf '#include<stdio.h>\nint main(){printf("cc OK!\\n");}' > t.c && cc t.c && ./a.out && rm -f t.c a.out 799b92b1d3SBarry Smith``` 809b92b1d3SBarry Smith 819b92b1d3SBarry Smith:::{note} 829b92b1d3SBarry SmithWhile it is recommended that you have functional C++ and Fortran compilers installed, 839b92b1d3SBarry Smiththey are not directly required to run PETSc in its default state. If they are 849b92b1d3SBarry Smithfunctioning, PETSc will automatically find them during the configure stage, however it 859b92b1d3SBarry Smithis always useful to test them on your own. 869b92b1d3SBarry Smith 879b92b1d3SBarry Smith```console 889b92b1d3SBarry Smith$ printf '#include<iostream>\nint main(){std::cout<<"c++ OK!"<<std::endl;}' > t.cpp && c++ t.cpp && ./a.out && rm -f t.cpp a.out 899b92b1d3SBarry Smith$ printf 'program t\nprint"(a)","gfortran OK!"\nend program' > t.f90 && gfortran t.f90 && ./a.out && rm -f t.f90 a.out 909b92b1d3SBarry Smith``` 919b92b1d3SBarry Smith::: 929b92b1d3SBarry Smith 939b92b1d3SBarry SmithIf compilers are working, each command should print out `<compiler_name> OK!` on the command 949b92b1d3SBarry Smithline. 959b92b1d3SBarry Smith 969b92b1d3SBarry Smith(tut_install_download)= 979b92b1d3SBarry Smith 989b92b1d3SBarry Smith## Downloading Source 999b92b1d3SBarry Smith 1009b92b1d3SBarry SmithSee the {ref}`download documentation <doc_download>` for additional details. 1019b92b1d3SBarry Smith 1029b92b1d3SBarry SmithWith all dependencies installed, navigate to a suitable directory on your machine and pull 1039b92b1d3SBarry Smiththe latest version of the PETSc library to your machine with git. The following commands 1049b92b1d3SBarry Smithwill create a directory "petsc" inside the current directory and retrieve the latest 1059b92b1d3SBarry Smithrelease branch of the repository. 1069b92b1d3SBarry Smith 1079b92b1d3SBarry Smith```console 1089b92b1d3SBarry Smith$ mkdir ~/projects 1099b92b1d3SBarry Smith$ cd ~/projects 1109b92b1d3SBarry Smith$ git clone -b release https://gitlab.com/petsc/petsc 1119b92b1d3SBarry Smith$ cd petsc 1129b92b1d3SBarry Smith``` 1139b92b1d3SBarry Smith 1149b92b1d3SBarry Smith:::{note} 1159b92b1d3SBarry SmithIf git is not available - or if pre-generated Fortran stubs are required (i.e avoid download and 1169b92b1d3SBarry Smithinstall of sowing package - that also requires a C++ compiler) one can download a release tarball. 1179b92b1d3SBarry SmithSee {ref}`download documentation <doc_download>` for additional details. 1189b92b1d3SBarry Smith::: 1199b92b1d3SBarry Smith 1209b92b1d3SBarry Smith:::{Warning} 1219b92b1d3SBarry SmithIt is **IMPERATIVE** to install PETSc in a directory whose path does not contain any of 1229b92b1d3SBarry Smiththe following special characters: 1239b92b1d3SBarry Smith 1249b92b1d3SBarry Smith\~ ! @ # \$ % ^ & * ( ) \` ; < > ? , [ ] { } ' " | (including spaces!) 1259b92b1d3SBarry Smith 1269b92b1d3SBarry SmithWhile PETSc is equipped to handle these errors, other installed dependencies may not be 1279b92b1d3SBarry Smithso well protected. 1289b92b1d3SBarry Smith::: 1299b92b1d3SBarry Smith 1309b92b1d3SBarry SmithThe download process may take a few minutes to complete. Successfully running this command 1319b92b1d3SBarry Smithshould yield a similar output: 1329b92b1d3SBarry Smith 1339b92b1d3SBarry Smith```console 1349b92b1d3SBarry Smith$ git clone -b release https://gitlab.com/petsc/petsc.git petsc 1359b92b1d3SBarry SmithCloning into 'petsc'... 1369b92b1d3SBarry Smithremote: Enumerating objects: 862597, done. 1379b92b1d3SBarry Smithremote: Counting objects: 100% (862597/862597), done. 1389b92b1d3SBarry Smithremote: Compressing objects: 100% (197622/197622), done. 1399b92b1d3SBarry Smithremote: Total 862597 (delta 660708), reused 862285 (delta 660444) 1409b92b1d3SBarry SmithReceiving objects: 100% (862597/862597), 205.11 MiB | 3.17 MiB/s, done. 1419b92b1d3SBarry SmithResolving deltas: 100% (660708/660708), done. 1429b92b1d3SBarry SmithUpdating files: 100% (7748/7748), done. 1439b92b1d3SBarry Smith$ cd petsc 1449b92b1d3SBarry Smith$ git pull # Not strictly necessary, but nice to check 1459b92b1d3SBarry SmithAlready up to date. 1469b92b1d3SBarry Smith``` 1479b92b1d3SBarry Smith 1489b92b1d3SBarry Smith(tut_install_config)= 1499b92b1d3SBarry Smith 1509b92b1d3SBarry Smith## Configuration 1519b92b1d3SBarry Smith 1529b92b1d3SBarry SmithSee {ref}`install documentation <doc_config_faq>` for more details. 1539b92b1d3SBarry Smith 1549b92b1d3SBarry SmithNext, PETSc needs to be configured using `configure` for your system with your 1559b92b1d3SBarry Smithspecific options. This is the stage where users can specify the exact parameters to 1569b92b1d3SBarry Smithcustomize their PETSc installation. Common configuration options are: 1579b92b1d3SBarry Smith 1589b92b1d3SBarry Smith- {ref}`Specifying different compilers. <doc_config_compilers>` 1599b92b1d3SBarry Smith- {ref}`Specifying different MPI implementations. <doc_config_mpi>` 1609b92b1d3SBarry Smith- Enabling [CUDA](https://developer.nvidia.com/cuda-toolkit)/[OpenCL](https://www.khronos.org/opencl/)/[ViennaCL](http://viennacl.sourceforge.net/) 1619b92b1d3SBarry Smith {ref}`support. <doc_config_accel>` 1629b92b1d3SBarry Smith- {ref}`Specifying options <doc_config_blaslapack>` for [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html). 1639b92b1d3SBarry Smith- {ref}`Specifying external packages <doc_config_externalpack>` to use or download 1649b92b1d3SBarry Smith automatically. PETSc can automatically download and install a wide range of other 1659b92b1d3SBarry Smith supporting software. 1669b92b1d3SBarry Smith- Setting various known machine quantities for PETSc to use such as known integral sizes, 1679b92b1d3SBarry Smith memory alignment, or additional compiler flags. 1689b92b1d3SBarry Smith 1699b92b1d3SBarry Smith:::{important} 1709b92b1d3SBarry SmithYou MUST specify all of your configuration options at this stage. In order to enable 1719b92b1d3SBarry Smithadditional options or packages in the future, you will have to reconfigure your PETSc 1729b92b1d3SBarry Smithinstallation in a similar manner with these options enabled. 1739b92b1d3SBarry Smith 1749b92b1d3SBarry SmithFor a full list of available options call 1759b92b1d3SBarry Smith 1769b92b1d3SBarry Smith```console 1779b92b1d3SBarry Smith$ ./configure --help 1789b92b1d3SBarry Smith``` 1799b92b1d3SBarry Smith::: 1809b92b1d3SBarry Smith 1819b92b1d3SBarry SmithAll PETSc options and flags follow the standard CLI formats `--option-string=<value>` or 1829b92b1d3SBarry Smith`--option-string`, where `<value>` is typically either `1` (for true) or `0` (for 1839b92b1d3SBarry Smithfalse) or a directory path. Directory paths must be absolute (i.e. full path from the root 1849b92b1d3SBarry Smithdirectory of your machine), but do accept environment variables as input. 1859b92b1d3SBarry Smith 1869b92b1d3SBarry SmithFrom `$PETSC_DIR` call the following `configure` command to configure PETSc as well 1879b92b1d3SBarry Smithas 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. 1889b92b1d3SBarry Smith 1899b92b1d3SBarry Smith```console 1909b92b1d3SBarry Smith$ ./configure --download-mpich --download-fblaslapack 1919b92b1d3SBarry Smith``` 1929b92b1d3SBarry Smith 1939b92b1d3SBarry SmithPETSc will begin configuring and printing its progress. A successful `configure` will 1949b92b1d3SBarry Smithhave the following general structure as its output: 1959b92b1d3SBarry Smith 1969b92b1d3SBarry Smith```text 1979b92b1d3SBarry Smith=============================================================================== 1989b92b1d3SBarry Smith Configuring PETSc to compile on your system 1999b92b1d3SBarry Smith=============================================================================== 2009b92b1d3SBarry SmithTESTING: configureSomething from PETSc.something(config/PETSc/configurescript.py:lineNUM) 2019b92b1d3SBarry Smith=============================================================================== 2029b92b1d3SBarry Smith Trying to download MPICH_DOWNLOAD_URL for MPICH 2039b92b1d3SBarry Smith=============================================================================== 2049b92b1d3SBarry Smith=============================================================================== 2059b92b1d3SBarry Smith Running configure on MPICH; this may take several minutes 2069b92b1d3SBarry Smith=============================================================================== 2079b92b1d3SBarry Smith=============================================================================== 2089b92b1d3SBarry Smith Running make on MPICH; this may take several minutes 2099b92b1d3SBarry Smith=============================================================================== 2109b92b1d3SBarry Smith=============================================================================== 2119b92b1d3SBarry Smith Running make install on MPICH; this may take several minutes 2129b92b1d3SBarry Smith=============================================================================== 2139b92b1d3SBarry Smith=============================================================================== 2149b92b1d3SBarry Smith Trying to download FBLASLAPACK_URL for FBLASLAPACK 2159b92b1d3SBarry Smith=============================================================================== 2169b92b1d3SBarry Smith=============================================================================== 2179b92b1d3SBarry Smith Compiling FBLASLAPACK; this may take several minutes 2189b92b1d3SBarry Smith=============================================================================== 2199b92b1d3SBarry Smith=============================================================================== 2209b92b1d3SBarry Smith Trying to download SOWING_DOWNLOAD_URL for SOWING 2219b92b1d3SBarry Smith=============================================================================== 2229b92b1d3SBarry Smith=============================================================================== 2239b92b1d3SBarry Smith Running configure on SOWING; this may take several minutes 2249b92b1d3SBarry Smith=============================================================================== 2259b92b1d3SBarry Smith=============================================================================== 2269b92b1d3SBarry Smith Running make on SOWING; this may take several minutes 2279b92b1d3SBarry Smith=============================================================================== 2289b92b1d3SBarry Smith=============================================================================== 2299b92b1d3SBarry Smith Running make install on SOWING; this may take several minutes 2309b92b1d3SBarry Smith=============================================================================== 2319b92b1d3SBarry SmithCompilers: 2329b92b1d3SBarry Smith C Compiler: Location information and flags 2339b92b1d3SBarry Smith C++ Compiler: Location information and flags 2349b92b1d3SBarry Smith. 2359b92b1d3SBarry Smith. 2369b92b1d3SBarry Smith. 2379b92b1d3SBarry SmithMPI: 2389b92b1d3SBarry Smith Includes: Include path 2399b92b1d3SBarry SmithOther Installed Packages: 2409b92b1d3SBarry Smith. 2419b92b1d3SBarry Smith. 2429b92b1d3SBarry Smith. 2439b92b1d3SBarry SmithPETSc: 2449b92b1d3SBarry Smith PETSC_ARCH: {YOUR_PETSC_ARCH} 2459b92b1d3SBarry Smith PETSC_DIR: {YOUR_PETSC_DIR} 2469b92b1d3SBarry Smith. 2479b92b1d3SBarry Smith. 2489b92b1d3SBarry Smith. 2499b92b1d3SBarry Smith. 2509b92b1d3SBarry Smith 2519b92b1d3SBarry Smithxxx=========================================================================xxx 2529b92b1d3SBarry SmithConfigure stage complete. Now build PETSc libraries with (gnumake build): 2539b92b1d3SBarry Smithmake PETSC_DIR=/your/petsc/dir PETSC_ARCH=your-petsc-arch all 2549b92b1d3SBarry Smithxxx=========================================================================xxx 2559b92b1d3SBarry Smith``` 2569b92b1d3SBarry Smith 2579b92b1d3SBarry Smith(tut_install_compile)= 2589b92b1d3SBarry Smith 2599b92b1d3SBarry Smith## Compilation 2609b92b1d3SBarry Smith 2619b92b1d3SBarry SmithAfter successfully configuring, build the binaries from source using the `make` 2629b92b1d3SBarry Smithcommand. This stage may take a few minutes, and will consume a great deal of system 2639b92b1d3SBarry Smithresources as the PETSc is compiled in parallel. 2649b92b1d3SBarry Smith 2659b92b1d3SBarry Smith```console 2669b92b1d3SBarry Smith$ make all check 2679b92b1d3SBarry Smith``` 2689b92b1d3SBarry Smith 2699b92b1d3SBarry SmithA successful `make` will provide an output of the following structure: 2709b92b1d3SBarry Smith 2719b92b1d3SBarry Smith```text 2729b92b1d3SBarry Smith----------------------------------------- 2739b92b1d3SBarry SmithPETSC_VERSION_RELEASE 2749b92b1d3SBarry Smith. 2759b92b1d3SBarry Smith. 2769b92b1d3SBarry Smith. 2779b92b1d3SBarry Smith----------------------------------------- 2789b92b1d3SBarry Smith#define SOME_PETSC_VARIABLE 2799b92b1d3SBarry Smith. 2809b92b1d3SBarry Smith. 2819b92b1d3SBarry Smith. 2829b92b1d3SBarry Smith----------------------------------------- 2839b92b1d3SBarry SmithInstalled Compiler, Package, and Library Information 2849b92b1d3SBarry Smith. 2859b92b1d3SBarry Smith. 2869b92b1d3SBarry Smith. 2879b92b1d3SBarry Smith========================================= 2886dd63270SBarry Smith FC arch-darwin-c-debug/obj/src/sys/ftn-mod/petscsysmod.o 2896dd63270SBarry Smith FC arch-darwin-c-debug/obj/src/sys/fsrc/somefort.o 2909b92b1d3SBarry Smith . 2919b92b1d3SBarry Smith . 2929b92b1d3SBarry Smith . 2936dd63270SBarry Smith FC arch-darwin-c-debug/obj/src/snes/ftn-mod/petscsnesmod.o 2946dd63270SBarry Smith FC arch-darwin-c-debug/obj/src/ts/ftn-mod/petsctsmod.o 2956dd63270SBarry Smith FC arch-darwin-c-debug/obj/src/tao/ftn-mod/petsctaomod.o 2969b92b1d3SBarry Smith CLINKER arch-darwin-c-debug/lib/libpetsc.PETSC_MAJOR.PETSC_MINOR.PETSC_PATCH.dylib 2979b92b1d3SBarry Smith DSYMUTIL arch-darwin-c-debug/lib/libpetsc.PETSC_MAJOR.PETSC_MINOR.PETSC_PATCH.dylib 2989b92b1d3SBarry Smithgmake[2]: Leaving directory '/your/petsc/dir' 2999b92b1d3SBarry Smithgmake[1]: Leaving directory '/your/petsc/dir' 3009b92b1d3SBarry Smith========================================= 3019b92b1d3SBarry SmithRunning test examples to verify correct installation 3029b92b1d3SBarry SmithUsing PETSC_DIR=/your/petsc/dir and PETSC_ARCH=your-petsc-arch 3039b92b1d3SBarry SmithC/C++ example src/snes/examples/tutorials/ex19 run successfully with 1 MPI process 3049b92b1d3SBarry SmithC/C++ example src/snes/examples/tutorials/ex19 run successfully with 2 MPI processes 3059b92b1d3SBarry SmithFortran example src/snes/examples/tutorials/ex5f run successfully with 1 MPI process 3069b92b1d3SBarry SmithCompleted test examples 3079b92b1d3SBarry Smith``` 3089b92b1d3SBarry Smith 3099b92b1d3SBarry Smith(tut_install_fin)= 3109b92b1d3SBarry Smith 3119b92b1d3SBarry Smith## Congratulations! 3129b92b1d3SBarry Smith 3139b92b1d3SBarry SmithYou now have a working PETSc installation and are ready to start using the library! 3149b92b1d3SBarry Smith 3159b92b1d3SBarry Smith```{rubric} Footnotes 3169b92b1d3SBarry Smith``` 3179b92b1d3SBarry Smith 3189b92b1d3SBarry Smith[^id5]: python2 is no longer supported. 3199b92b1d3SBarry Smith 3209b92b1d3SBarry Smith[^id6]: Should you be missing any of these dependencies or would like to update them, either 3219b92b1d3SBarry Smith download and install the latest versions from their respective websites, or use your 3229b92b1d3SBarry Smith preferred package manager to update them. For example, for macOS see {any}`doc_macos_install` 3239b92b1d3SBarry Smith 3249b92b1d3SBarry Smith[^blas]: The [BLAS/LAPACK](https://www.netlib.org/lapack/lug/node11.html) package 3259b92b1d3SBarry Smith installed as part of this tutorial is a [reference implementation](https://bitbucket.org/petsc/pkg-fblaslapack/src/master/) and a suitable starting 3269b92b1d3SBarry Smith point to get PETSc running, but is generally not as performant as more optimized 327*7f296bb3SBarry Smith libraries. See the {ref}`libaray guide <ch_blas_lapack_avail_libs>` for further 3289b92b1d3SBarry Smith details. 329