xref: /petsc/src/sys/objects/version.c (revision 1bd63e3efbce1229b47e2ec5bb1e7d27e9e9b2dd)
1 #include <petsc/private/petscimpl.h> /*I  "petscsys.h"   I*/
2 
3 /*@C
4   PetscGetVersion - Gets the PETSc version information in a string.
5 
6   Not Collective; No Fortran Support
7 
8   Input Parameter:
9 . len - length of the string
10 
11   Output Parameter:
12 . version - version string
13 
14   Level: developer
15 
16   Note:
17   For doing runtime checking of supported versions we recommend using `PetscGetVersionNumber()` instead of this routine.
18 
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 }
31 
32 /*@C
33   PetscGetVersionNumber - Gets the PETSc version information from the library
34 
35   Not Collective
36 
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)
42 
43   Level: developer
44 
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.
48 
49   This function can be called before `PetscInitialize()`
50 
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_MKL_SET_NUM_THREADS)
62   #include <mkl.h>
63 #elif defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS)
64   #pragma GCC diagnostic push
65   #pragma GCC diagnostic ignored "-Wunused-function"
66   #include <blis/blis.h>
67   #pragma GCC diagnostic pop
68 #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS)
69 EXTERN_C_BEGIN
70 void openblas_set_num_threads(int);
71 EXTERN_C_END
72 #endif
73 PetscInt PetscNumBLASThreads = 1;
74 
75 /*@
76   PetscBLASSetNumThreads - set the number of threads for calls to BLAS to use
77 
78   Input Parameter:
79 . nt - the number of threads
80 
81   Options Database Key:
82 . -blas_num_threads <nt> - set the number of threads when PETSc is initialized
83 
84   Level: intermediate
85 
86   Notes:
87   The environmental variables `BLIS_NUM_THREADS`, `MKL_NUM_THREADS`, or `OPENBLAS_NUM_THREADS`, `OMP_NUM_THREADS`
88   may also affect the number of threads used depending on the BLAS libraries being used. A call to this function
89   overwrites those values.
90 
91   With the BLIS BLAS implementation one can use `BLIS_THREAD_IMPL=pthread` or `BLIS_THREAD_IMPL=openmp` to determine how
92   BLIS implements the parallelism.
93 
94 .seealso: `PetscInitialize()`, `PetscBLASGetNumThreads()`
95 @*/
96 PetscErrorCode PetscBLASSetNumThreads(PetscInt nt)
97 {
98   PetscFunctionBegin;
99   PetscNumBLASThreads = nt;
100 #if defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS)
101   bli_thread_set_num_threads(nt);
102   PetscCall(PetscInfo(NULL, "Setting number of threads used for BLIS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
103 #elif defined(PETSC_HAVE_MKL_SET_NUM_THREADS)
104   mkl_set_num_threads((int)nt);
105   PetscCall(PetscInfo(NULL, "Setting number of threads used for MKL provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
106 #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS)
107   openblas_set_num_threads((int)nt);
108   PetscCall(PetscInfo(NULL, "Setting number of threads used for OpenBLAS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads));
109 #else
110   PetscCall(PetscInfo(NULL, "Cannot set number of threads used for BLAS %" PetscInt_FMT ", will be ignored\n", PetscNumBLASThreads));
111 #endif
112   PetscFunctionReturn(PETSC_SUCCESS);
113 }
114 
115 /*@
116   PetscBLASGetNumThreads - get the number of threads for calls to BLAS to use
117 
118   Output Parameter:
119 . nt - the number of threads
120 
121   Level: intermediate
122 
123 .seealso: `PetscInitialize()`, `PetscBLASSetNumThreads()`
124 @*/
125 PetscErrorCode PetscBLASGetNumThreads(PetscInt *nt)
126 {
127   PetscFunctionBegin;
128   PetscAssertPointer(nt, 1);
129   *nt = PetscNumBLASThreads;
130   PetscFunctionReturn(PETSC_SUCCESS);
131 }
132