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