Actual source code: version.c

  1: #include <petsc/private/petscimpl.h>

  3: /*@C
  4:   PetscGetVersion - Gets the PETSc version information in a string.

  6:   Not Collective; No Fortran Support

  8:   Input Parameter:
  9: . len - length of the string

 11:   Output Parameter:
 12: . version - version string

 14:   Level: developer

 16:   Note:
 17:   For doing runtime checking of supported versions we recommend using `PetscGetVersionNumber()` instead of this routine.

 19: .seealso: `PetscGetProgramName()`, `PetscGetVersionNumber()`
 20: @*/
 21: PetscErrorCode PetscGetVersion(char version[], size_t len)
 22: {
 23:   PetscFunctionBegin;
 24: #if (PETSC_VERSION_RELEASE == 1)
 25:   PetscCall(PetscSNPrintf(version, len, "Petsc Release Version %d.%d.%d, %s ", PETSC_VERSION_MAJOR, PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, PETSC_VERSION_DATE));
 26: #else
 27:   PetscCall(PetscSNPrintf(version, len, "Petsc Development GIT revision: %s  GIT Date: %s", PETSC_VERSION_GIT, PETSC_VERSION_DATE_GIT));
 28: #endif
 29:   PetscFunctionReturn(PETSC_SUCCESS);
 30: }

 32: /*@
 33:   PetscGetVersionNumber - Gets the PETSc version information from the library

 35:   Not Collective

 37:   Output Parameters:
 38: + major    - the major version (optional, pass `NULL` if not requested)
 39: . minor    - the minor version (optional, pass `NULL` if not requested)
 40: . subminor - the subminor version (patch number)  (optional, pass `NULL` if not requested)
 41: - release  - indicates the library is from a release, not random git repository  (optional, pass `NULL` if not requested)

 43:   Level: developer

 45:   Notes:
 46:   The C macros `PETSC_VERSION_MAJOR`, `PETSC_VERSION_MINOR`, `PETSC_VERSION_SUBMINOR`, `PETSC_VERSION_RELEASE` provide the information at
 47:   compile time. This can be used to confirm that the shared library being loaded at runtime has the appropriate version updates.

 49:   This function can be called before `PetscInitialize()`

 51: .seealso: `PetscGetProgramName()`, `PetscGetVersion()`, `PetscInitialize()`
 52: @*/
 53: PetscErrorCode PetscGetVersionNumber(PetscInt *major, PetscInt *minor, PetscInt *subminor, PetscInt *release)
 54: {
 55:   if (major) *major = PETSC_VERSION_MAJOR;
 56:   if (minor) *minor = PETSC_VERSION_MINOR;
 57:   if (subminor) *subminor = PETSC_VERSION_SUBMINOR;
 58:   if (release) *release = PETSC_VERSION_RELEASE;
 59:   return PETSC_SUCCESS;
 60: }
 61: #if defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS)
 62: EXTERN_C_BEGIN
 63: void bli_thread_set_num_threads(int);
 64: EXTERN_C_END
 65: #elif defined(PETSC_HAVE_MKL_SET_NUM_THREADS)
 66:   #include <mkl.h>
 67: #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS)
 68: EXTERN_C_BEGIN
 69: void openblas_set_num_threads(int);
 70: EXTERN_C_END
 71: #endif
 72: PetscInt PetscNumBLASThreads = 1;

 74: /*@
 75:   PetscBLASSetNumThreads - set the number of threads for calls to BLAS to use

 77:   Input Parameter:
 78: . nt - the number of threads

 80:   Options Database Key:
 81: . -blas_num_threads <nt> - set the number of threads when PETSc is initialized

 83:   Level: intermediate

 85:   Notes:
 86:   The environmental variables `BLIS_NUM_THREADS`, `MKL_NUM_THREADS`, or `OPENBLAS_NUM_THREADS`, `OMP_NUM_THREADS`
 87:   may also affect the number of threads used depending on the BLAS libraries being used. A call to this function
 88:   overwrites those values.

 90:   With the BLIS BLAS implementation one can use `BLIS_THREAD_IMPL=pthread` or `BLIS_THREAD_IMPL=openmp` to determine how
 91:   BLIS implements the parallelism.

 93: .seealso: `PetscInitialize()`, `PetscBLASGetNumThreads()`
 94: @*/
 95: PetscErrorCode PetscBLASSetNumThreads(PetscInt nt)
 96: {
 97:   PetscFunctionBegin;
 98:   PetscNumBLASThreads = nt;
 99: #if defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS)
100:   bli_thread_set_num_threads(nt);
101:   PetscCall(PetscInfo(NULL, "Setting number of threads used for BLIS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
102: #elif defined(PETSC_HAVE_MKL_SET_NUM_THREADS)
103:   mkl_set_num_threads((int)nt);
104:   PetscCall(PetscInfo(NULL, "Setting number of threads used for MKL provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
105: #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS)
106:   openblas_set_num_threads((int)nt);
107:   PetscCall(PetscInfo(NULL, "Setting number of threads used for OpenBLAS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
108: #else
109:   PetscCall(PetscInfo(NULL, "Cannot set number of threads used for BLAS %" PetscInt_FMT ", will be ignored\n", PetscNumBLASThreads));
110: #endif
111:   PetscFunctionReturn(PETSC_SUCCESS);
112: }

114: /*@
115:   PetscBLASGetNumThreads - get the number of threads for calls to BLAS to use

117:   Output Parameter:
118: . nt - the number of threads

120:   Level: intermediate

122: .seealso: `PetscInitialize()`, `PetscBLASSetNumThreads()`
123: @*/
124: PetscErrorCode PetscBLASGetNumThreads(PetscInt *nt)
125: {
126:   PetscFunctionBegin;
127:   PetscAssertPointer(nt, 1);
128:   *nt = PetscNumBLASThreads;
129:   PetscFunctionReturn(PETSC_SUCCESS);
130: }