Actual source code: version.c

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

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

  7:   Not Collective; No Fortran Support

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

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

 15:   Level: developer

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

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

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

 36:   Not Collective

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

 44:   Level: developer

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

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

 52: .seealso: `PetscGetProgramName()`, `PetscGetVersion()`, `PetscInitialize()`
 53: @*/
 54: PetscErrorCode PetscGetVersionNumber(PetscInt *major, PetscInt *minor, PetscInt *subminor, PetscInt *release)
 55: {
 56:   if (major) *major = PETSC_VERSION_MAJOR;
 57:   if (minor) *minor = PETSC_VERSION_MINOR;
 58:   if (subminor) *subminor = PETSC_VERSION_SUBMINOR;
 59:   if (release) *release = PETSC_VERSION_RELEASE;
 60:   return PETSC_SUCCESS;
 61: }

 63: /*@C
 64:   PetscGetConfiguration - Gets the PETSc configuration information in a string.

 66:   Not Collective

 68:   Output Parameter:
 69: . configuration - configuration string

 71:   Level: developer

 73: .seealso: `PetscGetProgramName()`, `PetscGetVersionNumber()`, `PetscGetVersion()`
 74: @*/
 75: PetscErrorCode PetscGetConfiguration(const char *configuration[])
 76: {
 77:   PetscFunctionBegin;
 78:   *configuration = petscconfigureoptions;
 79:   PetscFunctionReturn(PETSC_SUCCESS);
 80: }

 82: #if defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS)
 83: EXTERN_C_BEGIN
 84: void bli_thread_set_num_threads(int);
 85: EXTERN_C_END
 86: #elif defined(PETSC_HAVE_MKL_SET_NUM_THREADS)
 87:   #include <mkl.h>
 88: #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS)
 89: EXTERN_C_BEGIN
 90: void openblas_set_num_threads(int);
 91: EXTERN_C_END
 92: #endif
 93: PetscInt PetscNumBLASThreads = 1;

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

 98:   Input Parameter:
 99: . nt - the number of threads

101:   Options Database Key:
102: . -blas_num_threads nt - set the number of threads when PETSc is initialized

104:   Level: intermediate

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

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

114: .seealso: `PetscInitialize()`, `PetscBLASGetNumThreads()`
115: @*/
116: PetscErrorCode PetscBLASSetNumThreads(PetscInt nt)
117: {
118:   PetscFunctionBegin;
119:   PetscNumBLASThreads = nt;
120: #if defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS)
121:   bli_thread_set_num_threads(nt);
122:   PetscCall(PetscInfo(NULL, "Setting number of threads used for BLIS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
123: #elif defined(PETSC_HAVE_MKL_SET_NUM_THREADS)
124:   mkl_set_num_threads((int)nt);
125:   PetscCall(PetscInfo(NULL, "Setting number of threads used for MKL provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
126: #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS)
127:   openblas_set_num_threads((int)nt);
128:   PetscCall(PetscInfo(NULL, "Setting number of threads used for OpenBLAS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
129: #else
130:   PetscCall(PetscInfo(NULL, "Cannot set number of threads used for BLAS %" PetscInt_FMT ", will be ignored\n", PetscNumBLASThreads));
131: #endif
132:   PetscFunctionReturn(PETSC_SUCCESS);
133: }

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

138:   Output Parameter:
139: . nt - the number of threads

141:   Level: intermediate

143: .seealso: `PetscInitialize()`, `PetscBLASSetNumThreads()`
144: @*/
145: PetscErrorCode PetscBLASGetNumThreads(PetscInt *nt)
146: {
147:   PetscFunctionBegin;
148:   PetscAssertPointer(nt, 1);
149:   *nt = PetscNumBLASThreads;
150:   PetscFunctionReturn(PETSC_SUCCESS);
151: }