1*046ed546SBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 2*046ed546SBarry Smith 327710113SBarry Smith /*@C 427710113SBarry Smith PetscGetVersion - Gets the PETSc version information in a string. 527710113SBarry Smith 6cf53795eSBarry Smith Not Collective; No Fortran Support 7cf53795eSBarry Smith 827710113SBarry Smith Input Parameter: 927710113SBarry Smith . len - length of the string 1027710113SBarry Smith 1127710113SBarry Smith Output Parameter: 1227710113SBarry Smith . version - version string 1327710113SBarry Smith 1427710113SBarry Smith Level: developer 1527710113SBarry Smith 16811af0c4SBarry Smith Note: 17811af0c4SBarry Smith For doing runtime checking of supported versions we recommend using `PetscGetVersionNumber()` instead of this routine. 18811af0c4SBarry Smith 19db781477SPatrick Sanan .seealso: `PetscGetProgramName()`, `PetscGetVersionNumber()` 2027710113SBarry Smith @*/ 21d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscGetVersion(char version[], size_t len) 22d71ae5a4SJacob Faibussowitsch { 238cf9f3d7SBarry Smith PetscFunctionBegin; 2427710113SBarry Smith #if (PETSC_VERSION_RELEASE == 1) 259566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(version, len, "Petsc Release Version %d.%d.%d, %s ", PETSC_VERSION_MAJOR, PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, PETSC_VERSION_DATE)); 2627710113SBarry Smith #else 279566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(version, len, "Petsc Development GIT revision: %s GIT Date: %s", PETSC_VERSION_GIT, PETSC_VERSION_DATE_GIT)); 2827710113SBarry Smith #endif 293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3027710113SBarry Smith } 3127710113SBarry Smith 325f309d01SBarry Smith /*@C 335f309d01SBarry Smith PetscGetVersionNumber - Gets the PETSc version information from the library 345f309d01SBarry Smith 3520f4b53cSBarry Smith Not Collective 365f309d01SBarry Smith 37d8d19677SJose E. Roman Output Parameters: 3820f4b53cSBarry Smith + major - the major version (optional, pass `NULL` if not requested) 3920f4b53cSBarry Smith . minor - the minor version (optional, pass `NULL` if not requested) 4020f4b53cSBarry Smith . subminor - the subminor version (patch number) (optional, pass `NULL` if not requested) 4120f4b53cSBarry Smith - release - indicates the library is from a release, not random git repository (optional, pass `NULL` if not requested) 425f309d01SBarry Smith 435f309d01SBarry Smith Level: developer 445f309d01SBarry Smith 4595452b02SPatrick Sanan Notes: 46811af0c4SBarry Smith The C macros `PETSC_VERSION_MAJOR`, `PETSC_VERSION_MINOR`, `PETSC_VERSION_SUBMINOR`, `PETSC_VERSION_RELEASE` provide the information at 475f309d01SBarry Smith compile time. This can be used to confirm that the shared library being loaded at runtime has the appropriate version updates. 485f309d01SBarry Smith 49811af0c4SBarry Smith This function can be called before `PetscInitialize()` 508cf9f3d7SBarry Smith 51db781477SPatrick Sanan .seealso: `PetscGetProgramName()`, `PetscGetVersion()`, `PetscInitialize()` 525f309d01SBarry Smith @*/ 53d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscGetVersionNumber(PetscInt *major, PetscInt *minor, PetscInt *subminor, PetscInt *release) 54d71ae5a4SJacob Faibussowitsch { 555f309d01SBarry Smith if (major) *major = PETSC_VERSION_MAJOR; 565f309d01SBarry Smith if (minor) *minor = PETSC_VERSION_MINOR; 575f309d01SBarry Smith if (subminor) *subminor = PETSC_VERSION_SUBMINOR; 585f309d01SBarry Smith if (release) *release = PETSC_VERSION_RELEASE; 593ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 605f309d01SBarry Smith } 61*046ed546SBarry Smith #if defined(PETSC_HAVE_MKL_SET_NUM_THREADS) 62*046ed546SBarry Smith #include <mkl.h> 63*046ed546SBarry Smith #elif defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS) 64*046ed546SBarry Smith #pragma GCC diagnostic push 65*046ed546SBarry Smith #pragma GCC diagnostic ignored "-Wunused-function" 66*046ed546SBarry Smith #include <blis/blis.h> 67*046ed546SBarry Smith #pragma GCC diagnostic pop 68*046ed546SBarry Smith #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS) 69*046ed546SBarry Smith EXTERN_C_BEGIN 70*046ed546SBarry Smith void openblas_set_num_threads(int); 71*046ed546SBarry Smith EXTERN_C_END 72*046ed546SBarry Smith #endif 73*046ed546SBarry Smith PetscInt PetscNumBLASThreads = 1; 74*046ed546SBarry Smith 75*046ed546SBarry Smith /*@ 76*046ed546SBarry Smith PetscBLASSetNumThreads - set the number of threads for calls to BLAS to use 77*046ed546SBarry Smith 78*046ed546SBarry Smith Input Parameter: 79*046ed546SBarry Smith . nt - the number of threads 80*046ed546SBarry Smith 81*046ed546SBarry Smith Options Database Key: 82*046ed546SBarry Smith . -blas_num_threads <nt> - set the number of threads when PETSc is initialized 83*046ed546SBarry Smith 84*046ed546SBarry Smith Level: intermediate 85*046ed546SBarry Smith 86*046ed546SBarry Smith Notes: 87*046ed546SBarry Smith The environmental variables `BLIS_NUM_THREADS`, `MKL_NUM_THREADS`, or `OPENBLAS_NUM_THREADS`, `OMP_NUM_THREADS` 88*046ed546SBarry Smith may also affect the number of threads used depending on the BLAS libraries being used. A call to this function 89*046ed546SBarry Smith overwrites those values. 90*046ed546SBarry Smith 91*046ed546SBarry Smith With the BLIS BLAS implementation one can use `BLIS_THREAD_IMPL=pthread` or `BLIS_THREAD_IMPL=openmp` to determine how 92*046ed546SBarry Smith BLIS implements the parallelism. 93*046ed546SBarry Smith 94*046ed546SBarry Smith .seealso: `PetscInitialize()`, `PetscBLASGetNumThreads()` 95*046ed546SBarry Smith @*/ 96*046ed546SBarry Smith PetscErrorCode PetscBLASSetNumThreads(PetscInt nt) 97*046ed546SBarry Smith { 98*046ed546SBarry Smith PetscFunctionBegin; 99*046ed546SBarry Smith PetscNumBLASThreads = nt; 100*046ed546SBarry Smith #if defined(PETSC_HAVE_BLI_THREAD_SET_NUM_THREADS) 101*046ed546SBarry Smith bli_thread_set_num_threads(nt); 102*046ed546SBarry Smith PetscCall(PetscInfo(NULL, "Setting number of theads used for BLIS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads)); 103*046ed546SBarry Smith #elif defined(PETSC_HAVE_MKL_SET_NUM_THREADS) 104*046ed546SBarry Smith mkl_set_num_threads((int)nt); 105*046ed546SBarry Smith PetscCall(PetscInfo(NULL, "Setting number of theads used for MKL provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads)); 106*046ed546SBarry Smith #elif defined(PETSC_HAVE_OPENBLAS_SET_NUM_THREADS) 107*046ed546SBarry Smith openblas_set_num_threads((int)nt); 108*046ed546SBarry Smith PetscCall(PetscInfo(NULL, "Setting number of theads used for OpenBLAS provided BLAS %" PetscInt_FMT "\n", PetscNumBLASThreads)); 109*046ed546SBarry Smith #else 110*046ed546SBarry Smith PetscCall(PetscInfo(NULL, "Cannot set number of theads used for BLAS %" PetscInt_FMT ", will be ignored\n", PetscNumBLASThreads)); 111*046ed546SBarry Smith #endif 112*046ed546SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 113*046ed546SBarry Smith } 114*046ed546SBarry Smith 115*046ed546SBarry Smith /*@ 116*046ed546SBarry Smith PetscBLASGetNumThreads - get the number of threads for calls to BLAS to use 117*046ed546SBarry Smith 118*046ed546SBarry Smith Output Parameter: 119*046ed546SBarry Smith . nt - the number of threads 120*046ed546SBarry Smith 121*046ed546SBarry Smith Level: intermediate 122*046ed546SBarry Smith 123*046ed546SBarry Smith .seealso: `PetscInitialize()`, `PetscBLASSetNumThreads()` 124*046ed546SBarry Smith @*/ 125*046ed546SBarry Smith PetscErrorCode PetscBLASGetNumThreads(PetscInt *nt) 126*046ed546SBarry Smith { 127*046ed546SBarry Smith PetscFunctionBegin; 128*046ed546SBarry Smith PetscAssertPointer(nt, 1); 129*046ed546SBarry Smith *nt = PetscNumBLASThreads; 130*046ed546SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 131*046ed546SBarry Smith } 132