1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
(ch_versionchecking)=
# Checking the PETSc version
The PETSc version
is defined in `$PETSC_DIR/include/petscversion.h` with the three macros
`PETSC_VERSION_MAJOR`, `PETSC_VERSION_MINOR`, and `PETSC_VERSION_SUBMINOR`.
The shell commands `make getversion` or `$PETSC_DIR/lib/petsc/bin/petscversion` prints out the PETSc version.
The command
```console
$ $PETSC_DIR/lib/petsc/bin/petscversion <eq,gt,lt,ge,le> major.minor<.subminor>
```
allows one to add tests to make files, CMake files, configure scripts etc, to ensure the PETSc version is compatible with your applications. For example,
> ```console
> $ $PETSC_DIR/lib/petsc/bin/petscversion eq 3.22
> ```
returns 1 if the PETSc version is 3.22 (any subminor version is allowed). While
```console
$ $PETSC_DIR/lib/petsc/bin/petscversion ge 3.21
```
returns 1 if the PETSc version is 3.21 or higher.
Though we try to avoid making changes to the PETSc API, they are inevitable; thus we
provide tools to help manage one's application to be robust to such changes.
## During configure/make time
The command
```console
$ $PETSC_DIR/lib/petsc/bin/petscversion eq xxx.yyy[.zzz]
```
prints out 1 if the PETSc version matches `xxx.yyy[.zzz]` and 0 otherwise. The command works in a similar
way for `lt`, `le`, `gt`, and `ge`. This allows your application configure script, or `makefile` or `CMake` file
to check if the PETSc version is compatible with application even before beginning to compile your code.
## During compile time
The CPP macros
- `PETSC_VERSION_EQ(MAJOR,MINOR,SUBMINOR)`
- `PETSC_VERSION_LT(MAJOR,MINOR,SUBMINOR)`
- `PETSC_VERSION_LE(MAJOR,MINOR,SUBMINOR)`
- `PETSC_VERSION_GT(MAJOR,MINOR,SUBMINOR)`
- `PETSC_VERSION_GE(MAJOR,MINOR,SUBMINOR)`
may be used in the source code to choose different code paths or error out depending on the PETSc version.
## At Runtime
The command
```C
char version(lengthofversion);
PetscErrorCode PetscGetVersion(char version[], size_t lengthofversion)
```
gives access to the version at runtime.
|