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