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 @*/
PetscGetVersion(char version[],size_t len)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 /*@
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 @*/
PetscGetVersionNumber(PetscInt * major,PetscInt * minor,PetscInt * subminor,PetscInt * release)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;
73
74 /*@
75 PetscBLASSetNumThreads - set the number of threads for calls to BLAS to use
76
77 Input Parameter:
78 . nt - the number of threads
79
80 Options Database Key:
81 . -blas_num_threads <nt> - set the number of threads when PETSc is initialized
82
83 Level: intermediate
84
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.
89
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.
92
93 .seealso: `PetscInitialize()`, `PetscBLASGetNumThreads()`
94 @*/
PetscBLASSetNumThreads(PetscInt nt)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 }
113
114 /*@
115 PetscBLASGetNumThreads - get the number of threads for calls to BLAS to use
116
117 Output Parameter:
118 . nt - the number of threads
119
120 Level: intermediate
121
122 .seealso: `PetscInitialize()`, `PetscBLASSetNumThreads()`
123 @*/
PetscBLASGetNumThreads(PetscInt * nt)124 PetscErrorCode PetscBLASGetNumThreads(PetscInt *nt)
125 {
126 PetscFunctionBegin;
127 PetscAssertPointer(nt, 1);
128 *nt = PetscNumBLASThreads;
129 PetscFunctionReturn(PETSC_SUCCESS);
130 }
131