LCOV - code coverage report
Current view: top level - sys - slepcinit.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 89 101 88.1 %
Date: 2024-04-25 00:29:53 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : 
      11             : #include <slepc/private/slepcimpl.h>           /*I "slepcsys.h" I*/
      12             : 
      13             : #if defined(SLEPC_HAVE_HPDDM)
      14             : #include <petscksp.h>
      15             : SLEPC_EXTERN PetscErrorCode KSPCreate_HPDDM(KSP);
      16             : SLEPC_EXTERN PetscErrorCode PCCreate_HPDDM(PC);
      17             : #endif
      18             : 
      19             : /*@C
      20             :     SlepcGetVersion - Gets the SLEPc version information in a string.
      21             : 
      22             :     Not Collective
      23             : 
      24             :     Input Parameter:
      25             : .   len - length of the string
      26             : 
      27             :     Output Parameter:
      28             : .   version - version string
      29             : 
      30             :     Level: intermediate
      31             : 
      32             : .seealso: SlepcGetVersionNumber()
      33             : @*/
      34           2 : PetscErrorCode SlepcGetVersion(char version[],size_t len)
      35             : {
      36           2 :   PetscFunctionBegin;
      37             : #if (SLEPC_VERSION_RELEASE == 1)
      38             :   PetscCall(PetscSNPrintf(version,len,"SLEPc Release Version %d.%d.%d, %s",SLEPC_VERSION_MAJOR,SLEPC_VERSION_MINOR,SLEPC_VERSION_SUBMINOR,SLEPC_VERSION_DATE));
      39             : #else
      40           2 :   PetscCall(PetscSNPrintf(version,len,"SLEPc Development GIT revision: %s  GIT Date: %s",SLEPC_VERSION_GIT,SLEPC_VERSION_DATE_GIT));
      41             : #endif
      42           2 :   PetscFunctionReturn(PETSC_SUCCESS);
      43             : }
      44             : 
      45             : /*@C
      46             :     SlepcGetVersionNumber - Gets the SLEPc version information from the library.
      47             : 
      48             :     Not Collective
      49             : 
      50             :     Output Parameters:
      51             : +   major    - the major version
      52             : .   minor    - the minor version
      53             : .   subminor - the subminor version (patch number)
      54             : -   release  - indicates the library is from a release
      55             : 
      56             :     Notes:
      57             :     Pass NULL in any argument that is not requested.
      58             : 
      59             :     The C macros SLEPC_VERSION_MAJOR, SLEPC_VERSION_MINOR, SLEPC_VERSION_SUBMINOR,
      60             :     SLEPC_VERSION_RELEASE provide the information at compile time. This can be used to confirm
      61             :     that the shared library being loaded at runtime has the appropriate version updates.
      62             : 
      63             :     This function can be called before SlepcInitialize().
      64             : 
      65             :     Level: intermediate
      66             : 
      67             : .seealso: SlepcGetVersion(), SlepcInitialize()
      68             : @*/
      69           1 : PetscErrorCode SlepcGetVersionNumber(PetscInt *major,PetscInt *minor,PetscInt *subminor,PetscInt *release)
      70             : {
      71           1 :   if (major)    *major    = SLEPC_VERSION_MAJOR;
      72           1 :   if (minor)    *minor    = SLEPC_VERSION_MINOR;
      73           1 :   if (subminor) *subminor = SLEPC_VERSION_SUBMINOR;
      74           1 :   if (release)  *release  = SLEPC_VERSION_RELEASE;
      75           1 :   return PETSC_SUCCESS;
      76             : }
      77             : 
      78             : /*
      79             :    SlepcPrintVersion - Prints SLEPc version info.
      80             : 
      81             :    Collective
      82             : */
      83           1 : static PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
      84             : {
      85           1 :   char           version[256];
      86             : 
      87           1 :   PetscFunctionBegin;
      88           1 :   PetscCall(SlepcGetVersion(version,256));
      89           1 :   PetscCall((*PetscHelpPrintf)(comm,"%s\n",version));
      90           1 :   PetscCall((*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO));
      91           1 :   PetscCall((*PetscHelpPrintf)(comm,"See https://slepc.upv.es/documentation/ for help.\n"));
      92           1 :   PetscCall((*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR));
      93           1 :   PetscFunctionReturn(PETSC_SUCCESS);
      94             : }
      95             : 
      96             : /*
      97             :    SlepcPrintHelpIntro - Prints introductory SLEPc help info.
      98             : 
      99             :    Collective
     100             : */
     101           1 : static PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
     102             : {
     103           1 :   PetscFunctionBegin;
     104           1 :   PetscCall((*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n"));
     105           1 :   PetscCall((*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n"));
     106           1 :   PetscCall((*PetscHelpPrintf)(comm,"----------------------------------------\n"));
     107           1 :   PetscFunctionReturn(PETSC_SUCCESS);
     108             : }
     109             : 
     110             : /* ------------------------Nasty global variables -------------------------------*/
     111             : /*
     112             :    Indicates whether SLEPc started PETSc, or whether it was
     113             :    already started before SLEPc was initialized.
     114             : */
     115             : PetscBool SlepcBeganPetsc       = PETSC_FALSE;
     116             : PetscBool SlepcInitializeCalled = PETSC_FALSE;
     117             : PetscBool SlepcFinalizeCalled   = PETSC_FALSE;
     118             : 
     119             : #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
     120           1 : static PetscErrorCode SlepcLoadDynamicLibrary(const char *name,PetscBool *found)
     121             : {
     122           1 :   char           libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
     123             : 
     124           1 :   PetscFunctionBegin;
     125           1 :   PetscCall(PetscStrcpy(libs,SLEPC_LIB_DIR));
     126           1 :   PetscCall(PetscStrlcat(libs,"/libslepc",sizeof(libs)));
     127           1 :   PetscCall(PetscStrlcat(libs,name,sizeof(libs)));
     128           1 :   PetscCall(PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,sizeof(dlib),found));
     129           1 :   if (*found) PetscCall(PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib));
     130           1 :   PetscFunctionReturn(PETSC_SUCCESS);
     131             : }
     132             : #endif
     133             : 
     134             : #if defined(PETSC_USE_SINGLE_LIBRARY) && !(defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES))
     135             : SLEPC_EXTERN PetscErrorCode STInitializePackage(void);
     136             : SLEPC_EXTERN PetscErrorCode DSInitializePackage(void);
     137             : SLEPC_EXTERN PetscErrorCode FNInitializePackage(void);
     138             : SLEPC_EXTERN PetscErrorCode BVInitializePackage(void);
     139             : SLEPC_EXTERN PetscErrorCode RGInitializePackage(void);
     140             : SLEPC_EXTERN PetscErrorCode EPSInitializePackage(void);
     141             : SLEPC_EXTERN PetscErrorCode SVDInitializePackage(void);
     142             : SLEPC_EXTERN PetscErrorCode PEPInitializePackage(void);
     143             : SLEPC_EXTERN PetscErrorCode NEPInitializePackage(void);
     144             : SLEPC_EXTERN PetscErrorCode MFNInitializePackage(void);
     145             : SLEPC_EXTERN PetscErrorCode LMEInitializePackage(void);
     146             : #endif
     147             : 
     148             : /*
     149             :     SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
     150             :     search path.
     151             : */
     152        1524 : PetscErrorCode SlepcInitialize_DynamicLibraries(void)
     153             : {
     154        1524 :   PetscBool      preload = PETSC_FALSE;
     155             : 
     156        1524 :   PetscFunctionBegin;
     157             : #if defined(PETSC_HAVE_THREADSAFETY)
     158             :   /* These must be all initialized here because it is not safe for individual threads to call these initialize routines */
     159             :   preload = PETSC_TRUE;
     160             : #endif
     161             : 
     162        1524 :   PetscCall(PetscOptionsGetBool(NULL,NULL,"-library_preload",&preload,NULL));
     163        1524 :   if (preload) {
     164             : #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
     165           1 :     PetscBool found;
     166             : #if defined(PETSC_USE_SINGLE_LIBRARY)
     167           1 :     PetscCall(SlepcLoadDynamicLibrary("",&found));
     168           1 :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library. You cannot move the dynamic libraries!");
     169             : #else
     170             :     PetscCall(SlepcLoadDynamicLibrary("sys",&found));
     171             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc sys dynamic library. You cannot move the dynamic libraries!");
     172             :     PetscCall(SlepcLoadDynamicLibrary("eps",&found));
     173             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc EPS dynamic library. You cannot move the dynamic libraries!");
     174             :     PetscCall(SlepcLoadDynamicLibrary("pep",&found));
     175             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc PEP dynamic library. You cannot move the dynamic libraries!");
     176             :     PetscCall(SlepcLoadDynamicLibrary("nep",&found));
     177             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc NEP dynamic library. You cannot move the dynamic libraries!");
     178             :     PetscCall(SlepcLoadDynamicLibrary("svd",&found));
     179             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc SVD dynamic library. You cannot move the dynamic libraries!");
     180             :     PetscCall(SlepcLoadDynamicLibrary("mfn",&found));
     181             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc MFN dynamic library. You cannot move the dynamic libraries!");
     182             :     PetscCall(SlepcLoadDynamicLibrary("lme",&found));
     183             :     PetscCheck(found,PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc LME dynamic library. You cannot move the dynamic libraries!");
     184             : #endif
     185             : #else /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
     186             : #if defined(PETSC_USE_SINGLE_LIBRARY)
     187             :   PetscCall(STInitializePackage());
     188             :   PetscCall(DSInitializePackage());
     189             :   PetscCall(FNInitializePackage());
     190             :   PetscCall(BVInitializePackage());
     191             :   PetscCall(RGInitializePackage());
     192             :   PetscCall(EPSInitializePackage());
     193             :   PetscCall(SVDInitializePackage());
     194             :   PetscCall(PEPInitializePackage());
     195             :   PetscCall(NEPInitializePackage());
     196             :   PetscCall(MFNInitializePackage());
     197             :   PetscCall(LMEInitializePackage());
     198             : #else
     199             :   SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Cannot use -library_preload with multiple static SLEPc libraries");
     200             : #endif
     201             : #endif /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
     202             :   }
     203             : 
     204             : #if defined(SLEPC_HAVE_HPDDM)
     205        1524 :   PetscCall(KSPRegister(KSPHPDDM,KSPCreate_HPDDM));
     206        1524 :   PetscCall(PCRegister(PCHPDDM,PCCreate_HPDDM));
     207             : #endif
     208        1524 :   PetscFunctionReturn(PETSC_SUCCESS);
     209             : }
     210             : 
     211        1524 : PetscErrorCode SlepcCitationsInitialize(void)
     212             : {
     213        1524 :   PetscFunctionBegin;
     214        1524 :   PetscCall(PetscCitationsRegister("@Article{slepc-toms,\n"
     215             :     "   author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
     216             :     "   title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
     217             :     "   journal = \"{ACM} Trans. Math. Software\",\n"
     218             :     "   volume = \"31\",\n"
     219             :     "   number = \"3\",\n"
     220             :     "   pages = \"351--362\",\n"
     221             :     "   year = \"2005\",\n"
     222             :     "   doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
     223             :     "}\n",NULL));
     224        1524 :   PetscCall(PetscCitationsRegister("@TechReport{slepc-manual,\n"
     225             :     "   author = \"J. E. Roman and C. Campos and L. Dalcin and E. Romero and A. Tomas\",\n"
     226             :     "   title = \"{SLEPc} Users Manual\",\n"
     227             :     "   number = \"DSIC-II/24/02 - Revision 3.21\",\n"
     228             :     "   institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
     229             :     "   year = \"2024\"\n"
     230             :     "}\n",NULL));
     231        1524 :   PetscFunctionReturn(PETSC_SUCCESS);
     232             : }
     233             : 
     234             : /*@C
     235             :    SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
     236             :    PetscInitialize() if that has not been called yet, so this routine should
     237             :    always be called near the beginning of your program.
     238             : 
     239             :    Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
     240             : 
     241             :    Input Parameters:
     242             : +  argc - count of number of command line arguments
     243             : .  args - the command line arguments
     244             : .  file - [optional] PETSc database file, defaults to ~username/.petscrc
     245             :           (use NULL for default)
     246             : -  help - [optional] Help message to print, use NULL for no message
     247             : 
     248             :    Fortran Notes:
     249             :    Fortran syntax is very similar to that of PetscInitialize()
     250             : 
     251             :    Level: beginner
     252             : 
     253             : .seealso: SlepcFinalize(), PetscInitialize(), SlepcInitializeFortran()
     254             : @*/
     255        1532 : PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
     256             : {
     257        1532 :   PetscBool      flg;
     258             : 
     259        1532 :   PetscFunctionBegin;
     260        1532 :   if (SlepcInitializeCalled) PetscFunctionReturn(PETSC_SUCCESS);
     261        1524 :   PetscCall(PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion));
     262        1524 :   PetscCall(PetscInitialized(&flg));
     263        1524 :   if (!flg) {
     264        1522 :     PetscCall(PetscInitialize(argc,args,file,help));
     265        1522 :     SlepcBeganPetsc = PETSC_TRUE;
     266             :   }
     267             : 
     268        1524 :   PetscCall(SlepcCitationsInitialize());
     269             : 
     270             :   /* Load the dynamic libraries (on machines that support them), this registers all the solvers etc. */
     271        1524 :   PetscCall(SlepcInitialize_DynamicLibraries());
     272             : 
     273        1524 :   SlepcInitializeCalled = PETSC_TRUE;
     274        1524 :   SlepcFinalizeCalled   = PETSC_FALSE;
     275        1524 :   PetscCall(PetscInfo(0,"SLEPc successfully started\n"));
     276        1524 :   PetscFunctionReturn(PETSC_SUCCESS);
     277             : }
     278             : 
     279             : /*@C
     280             :    SlepcFinalize - Checks for options to be called at the conclusion
     281             :    of the SLEPc program and calls PetscFinalize().
     282             : 
     283             :    Collective on PETSC_COMM_WORLD
     284             : 
     285             :    Level: beginner
     286             : 
     287             : .seealso: SlepcInitialize(), PetscFinalize()
     288             : @*/
     289        1523 : PetscErrorCode SlepcFinalize(void)
     290             : {
     291        1523 :   PetscFunctionBegin;
     292        1523 :   if (PetscUnlikely(!SlepcInitializeCalled)) {
     293           0 :     fprintf(PETSC_STDOUT,"SlepcInitialize() must be called before SlepcFinalize()\n");
     294           0 :     PetscStackClearTop;
     295           0 :     return PETSC_ERR_ARG_WRONGSTATE;
     296             :   }
     297        1523 :   PetscCall(PetscInfo(NULL,"SlepcFinalize() called\n"));
     298        1523 :   if (SlepcBeganPetsc) {
     299        1522 :     PetscCall(PetscFinalize());
     300           0 :     SlepcBeganPetsc = PETSC_FALSE;
     301             :   }
     302           1 :   SlepcInitializeCalled = PETSC_FALSE;
     303           1 :   SlepcFinalizeCalled   = PETSC_TRUE;
     304           1 :   PetscStackClearTop;
     305           1 :   return PETSC_SUCCESS;
     306             : }
     307             : 
     308             : /*@C
     309             :    SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
     310             :    the command line arguments.
     311             : 
     312             :    Collective
     313             : 
     314             :    Level: advanced
     315             : 
     316             : .seealso: SlepcInitialize(), SlepcInitializeFortran()
     317             : @*/
     318           9 : PetscErrorCode SlepcInitializeNoArguments(void)
     319             : {
     320           9 :   int  argc = 0;
     321           9 :   char **args = NULL;
     322             : 
     323           9 :   PetscFunctionBegin;
     324           9 :   PetscCall(SlepcInitialize(&argc,&args,NULL,NULL));
     325           9 :   PetscFunctionReturn(PETSC_SUCCESS);
     326             : }
     327             : 
     328             : /*@
     329             :    SlepcInitialized - Determine whether SLEPc is initialized.
     330             : 
     331             :    Output Parameter:
     332             : .  isInitialized - the result
     333             : 
     334             :    Level: beginner
     335             : 
     336             : .seealso: SlepcInitialize(), SlepcInitializeFortran()
     337             : @*/
     338          14 : PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
     339             : {
     340          14 :   PetscFunctionBegin;
     341          14 :   *isInitialized = SlepcInitializeCalled;
     342          14 :   PetscFunctionReturn(PETSC_SUCCESS);
     343             : }
     344             : 
     345             : /*@
     346             :    SlepcFinalized - Determine whether SlepcFinalize() has been called.
     347             : 
     348             :    Output Parameter:
     349             : .  isFinalized - the result
     350             : 
     351             :    Level: developer
     352             : 
     353             : .seealso: SlepcFinalize()
     354             : @*/
     355           3 : PetscErrorCode SlepcFinalized(PetscBool *isFinalized)
     356             : {
     357           3 :   PetscFunctionBegin;
     358           3 :   *isFinalized = SlepcFinalizeCalled;
     359           3 :   PetscFunctionReturn(PETSC_SUCCESS);
     360             : }
     361             : 
     362             : PETSC_EXTERN PetscBool PetscBeganMPI;
     363             : 
     364             : /*@C
     365             :    SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
     366             :    to argc and args (analogue to PetscInitializeNoPointers).
     367             : 
     368             :    Collective
     369             : 
     370             :    Input Parameters:
     371             : +  argc - count of number of command line arguments
     372             : .  args - the command line arguments
     373             : .  file - [optional] PETSc database file, defaults to ~username/.petscrc
     374             :           (use NULL for default)
     375             : -  help - [optional] Help message to print, use NULL for no message
     376             : 
     377             :    Level: advanced
     378             : 
     379             : .seealso: SlepcInitialize()
     380             : @*/
     381           0 : PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *file,const char *help)
     382             : {
     383           0 :   int            myargc = argc;
     384           0 :   char           **myargs = args;
     385             : 
     386           0 :   PetscFunctionBegin;
     387           0 :   PetscCall(SlepcInitialize(&myargc,&myargs,file,help));
     388           0 :   PetscCall(PetscPopSignalHandler());
     389           0 :   PetscBeganMPI = PETSC_FALSE;
     390           0 :   PetscFunctionReturn(PETSC_SUCCESS);
     391             : }

Generated by: LCOV version 1.14