Date: 2023-01-26T12:17:48+00:00

Actual source code: slepcinit.c
slepc-3.18.2 2023-01-26
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */

     11: #include <slepc/private/slepcimpl.h>

     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

     19: /*@C
     20:     SlepcGetVersion - Gets the SLEPc version information in a string.

     22:     Not collective

     24:     Input Parameter:
     25: .   len - length of the string

     27:     Output Parameter:
     28: .   version - version string

     30:     Level: intermediate

     32: .seealso: SlepcGetVersionNumber()
     33: @*/
     34: PetscErrorCode SlepcGetVersion(char version[],size_t len)
     35: {
     36: #if (SLEPC_VERSION_RELEASE == 1)
     37:   PetscSNPrintf(version,len,"SLEPc Release Version %d.%d.%d, %s",SLEPC_VERSION_MAJOR,SLEPC_VERSION_MINOR,SLEPC_VERSION_SUBMINOR,SLEPC_VERSION_DATE);
     38: #else
     39:   PetscSNPrintf(version,len,"SLEPc Development GIT revision: %s  GIT Date: %s",SLEPC_VERSION_GIT,SLEPC_VERSION_DATE_GIT);
     40: #endif
     41:   return 0;
     42: }

     44: /*@C
     45:     SlepcGetVersionNumber - Gets the SLEPc version information from the library.

     47:     Not collective

     49:     Output Parameters:
     50: +   major    - the major version
     51: .   minor    - the minor version
     52: .   subminor - the subminor version (patch number)
     53: -   release  - indicates the library is from a release

     55:     Notes:
     56:     Pass NULL in any argument that is not requested.

     58:     The C macros SLEPC_VERSION_MAJOR, SLEPC_VERSION_MINOR, SLEPC_VERSION_SUBMINOR,
     59:     SLEPC_VERSION_RELEASE provide the information at compile time. This can be used to confirm
     60:     that the shared library being loaded at runtime has the appropriate version updates.

     62:     This function can be called before SlepcInitialize().

     64:     Level: intermediate

     66: .seealso: SlepcGetVersion(), SlepcInitialize()
     67: @*/
     68: PetscErrorCode SlepcGetVersionNumber(PetscInt *major,PetscInt *minor,PetscInt *subminor,PetscInt *release)
     69: {
     70:   if (major)    *major    = SLEPC_VERSION_MAJOR;
     71:   if (minor)    *minor    = SLEPC_VERSION_MINOR;
     72:   if (subminor) *subminor = SLEPC_VERSION_SUBMINOR;
     73:   if (release)  *release  = SLEPC_VERSION_RELEASE;
     74:   return 0;
     75: }

     77: /*
     78:    SlepcPrintVersion - Prints SLEPc version info.

     80:    Collective
     81: */
     82: static PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
     83: {
     84:   char           version[256];

     86:   SlepcGetVersion(version,256);
     87:   (*PetscHelpPrintf)(comm,"%s\n",version);
     88:   (*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO);
     89:   (*PetscHelpPrintf)(comm,"See docs/manual.html for help.\n");
     90:   (*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR);
     91:   return 0;
     92: }

     94: /*
     95:    SlepcPrintHelpIntro - Prints introductory SLEPc help info.

     97:    Collective
     98: */
     99: static PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
    100: {
    101:   (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
    102:   (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
    103:   (*PetscHelpPrintf)(comm,"----------------------------------------\n");
    104:   return 0;
    105: }

    107: /* ------------------------Nasty global variables -------------------------------*/
    108: /*
    109:    Indicates whether SLEPc started PETSc, or whether it was
    110:    already started before SLEPc was initialized.
    111: */
    112: PetscBool SlepcBeganPetsc       = PETSC_FALSE;
    113: PetscBool SlepcInitializeCalled = PETSC_FALSE;
    114: PetscBool SlepcFinalizeCalled   = PETSC_FALSE;

    116: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
    117: static PetscErrorCode SlepcLoadDynamicLibrary(const char *name,PetscBool *found)
    118: {
    119:   char           libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];

    121:   PetscStrcpy(libs,SLEPC_LIB_DIR);
    122:   PetscStrlcat(libs,"/libslepc",sizeof(libs));
    123:   PetscStrlcat(libs,name,sizeof(libs));
    124:   PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,sizeof(dlib),found);
    125:   if (*found) PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
    126:   return 0;
    127: }
    128: #endif

    130: #if defined(PETSC_USE_SINGLE_LIBRARY) && !(defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES))
    131: SLEPC_EXTERN PetscErrorCode STInitializePackage(void);
    132: SLEPC_EXTERN PetscErrorCode DSInitializePackage(void);
    133: SLEPC_EXTERN PetscErrorCode FNInitializePackage(void);
    134: SLEPC_EXTERN PetscErrorCode BVInitializePackage(void);
    135: SLEPC_EXTERN PetscErrorCode RGInitializePackage(void);
    136: SLEPC_EXTERN PetscErrorCode EPSInitializePackage(void);
    137: SLEPC_EXTERN PetscErrorCode SVDInitializePackage(void);
    138: SLEPC_EXTERN PetscErrorCode PEPInitializePackage(void);
    139: SLEPC_EXTERN PetscErrorCode NEPInitializePackage(void);
    140: SLEPC_EXTERN PetscErrorCode MFNInitializePackage(void);
    141: SLEPC_EXTERN PetscErrorCode LMEInitializePackage(void);
    142: #endif

    144: /*
    145:     SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
    146:     search path.
    147: */
    148: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
    149: {
    150:   PetscBool      preload = PETSC_FALSE;

    152: #if defined(PETSC_HAVE_THREADSAFETY)
    153:   /* These must be all initialized here because it is not safe for individual threads to call these initialize routines */
    154:   preload = PETSC_TRUE;
    155: #endif

    157:   PetscOptionsGetBool(NULL,NULL,"-library_preload",&preload,NULL);
    158:   if (preload) {
    159: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
    160:     PetscBool found;
    161: #if defined(PETSC_USE_SINGLE_LIBRARY)
    162:     SlepcLoadDynamicLibrary("",&found);
    164: #else
    165:     SlepcLoadDynamicLibrary("sys",&found);
    167:     SlepcLoadDynamicLibrary("eps",&found);
    169:     SlepcLoadDynamicLibrary("pep",&found);
    171:     SlepcLoadDynamicLibrary("nep",&found);
    173:     SlepcLoadDynamicLibrary("svd",&found);
    175:     SlepcLoadDynamicLibrary("mfn",&found);
    177:     SlepcLoadDynamicLibrary("lme",&found);
    179: #endif
    180: #else /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
    181: #if defined(PETSC_USE_SINGLE_LIBRARY)
    182:   STInitializePackage();
    183:   DSInitializePackage();
    184:   FNInitializePackage();
    185:   BVInitializePackage();
    186:   RGInitializePackage();
    187:   EPSInitializePackage();
    188:   SVDInitializePackage();
    189:   PEPInitializePackage();
    190:   NEPInitializePackage();
    191:   MFNInitializePackage();
    192:   LMEInitializePackage();
    193: #else
    194:   SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Cannot use -library_preload with multiple static SLEPc libraries");
    195: #endif
    196: #endif /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
    197:   }

    199: #if defined(SLEPC_HAVE_HPDDM)
    200:   KSPRegister(KSPHPDDM,KSPCreate_HPDDM);
    201:   PCRegister(PCHPDDM,PCCreate_HPDDM);
    202: #endif
    203:   return 0;
    204: }

    206: PetscErrorCode SlepcCitationsInitialize(void)
    207: {
    208:   PetscCall(PetscCitationsRegister("@Article{slepc-toms,\n"
    209:     "   author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
    210:     "   title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
    211:     "   journal = \"{ACM} Trans. Math. Software\",\n"
    212:     "   volume = \"31\",\n"
    213:     "   number = \"3\",\n"
    214:     "   pages = \"351--362\",\n"
    215:     "   year = \"2005,\"\n"
    216:     "   doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
    217:     "}\n",NULL));
    218:   PetscCall(PetscCitationsRegister("@TechReport{slepc-manual,\n"
    219:     "   author = \"J. E. Roman and C. Campos and L. Dalcin and E. Romero and A. Tomas\",\n"
    220:     "   title = \"{SLEPc} Users Manual\",\n"
    221:     "   number = \"DSIC-II/24/02 - Revision 3.18\",\n"
    222:     "   institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
    223:     "   year = \"2022\"\n"
    224:     "}\n",NULL));
    225:   return 0;
    226: }

    228: /*@C
    229:    SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
    230:    PetscInitialize() if that has not been called yet, so this routine should
    231:    always be called near the beginning of your program.

    233:    Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set

    235:    Input Parameters:
    236: +  argc - count of number of command line arguments
    237: .  args - the command line arguments
    238: .  file - [optional] PETSc database file, defaults to ~username/.petscrc
    239:           (use NULL for default)
    240: -  help - [optional] Help message to print, use NULL for no message

    242:    Fortran Notes:
    243:    Fortran syntax is very similar to that of PetscInitialize()

    245:    Level: beginner

    247: .seealso: SlepcFinalize(), PetscInitialize()
    248: @*/
    249: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
    250: {
    251:   PetscBool      flg;

    253:   if (SlepcInitializeCalled) return 0;
    254:   PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
    255:   PetscInitialized(&flg);
    256:   if (!flg) {
    257:     PetscInitialize(argc,args,file,help);
    258:     SlepcBeganPetsc = PETSC_TRUE;
    259:   }

    261:   SlepcCitationsInitialize();

    263:   /* Load the dynamic libraries (on machines that support them), this registers all the solvers etc. */
    264:   SlepcInitialize_DynamicLibraries();

    266:   SlepcInitializeCalled = PETSC_TRUE;
    267:   SlepcFinalizeCalled   = PETSC_FALSE;
    268:   PetscInfo(0,"SLEPc successfully started\n");
    269:   return 0;
    270: }

    272: /*@C
    273:    SlepcFinalize - Checks for options to be called at the conclusion
    274:    of the SLEPc program and calls PetscFinalize().

    276:    Collective on PETSC_COMM_WORLD

    278:    Level: beginner

    280: .seealso: SlepcInitialize(), PetscFinalize()
    281: @*/
    282: PetscErrorCode SlepcFinalize(void)
    283: {
    284:   if (PetscUnlikely(!SlepcInitializeCalled)) {
    285:     fprintf(PETSC_STDOUT,"SlepcInitialize() must be called before SlepcFinalize()\n");
    286:     PetscStackClearTop;
    287:     return PETSC_ERR_ARG_WRONGSTATE;
    288:   }
    289:   PetscInfo(NULL,"SlepcFinalize() called\n");
    290:   if (SlepcBeganPetsc) {
    291:     PetscFinalize();
    292:     SlepcBeganPetsc = PETSC_FALSE;
    293:   }
    294:   SlepcInitializeCalled = PETSC_FALSE;
    295:   SlepcFinalizeCalled   = PETSC_TRUE;
    297:   PetscStackClearTop;
    298:   return 0;
    299: }

    301: /*@C
    302:    SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
    303:    the command line arguments.

    305:    Collective

    307:    Level: advanced

    309: .seealso: SlepcInitialize(), SlepcInitializeFortran()
    310: @*/
    311: PetscErrorCode SlepcInitializeNoArguments(void)
    312: {
    313:   int  argc = 0;
    314:   char **args = NULL;

    316:   SlepcInitialize(&argc,&args,NULL,NULL);
    317:   return 0;
    318: }

    320: /*@
    321:    SlepcInitialized - Determine whether SLEPc is initialized.

    323:    Output Parameter:
    324: .  isInitialized - the result

    326:    Level: beginner

    328: .seealso: SlepcInitialize(), SlepcInitializeFortran()
    329: @*/
    330: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
    331: {
    332:   *isInitialized = SlepcInitializeCalled;
    333:   return 0;
    334: }

    336: /*@
    337:    SlepcFinalized - Determine whether SlepcFinalize() has been called.

    339:    Output Parameter:
    340: .  isFinalized - the result

    342:    Level: developer

    344: .seealso: SlepcFinalize()
    345: @*/
    346: PetscErrorCode SlepcFinalized(PetscBool *isFinalized)
    347: {
    348:   *isFinalized = SlepcFinalizeCalled;
    349:   return 0;
    350: }

    352: PETSC_EXTERN PetscBool PetscBeganMPI;

    354: /*@C
    355:    SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
    356:    to argc and args (analogue to PetscInitializeNoPointers).

    358:    Collective

    360:    Input Parameters:
    361: +  argc - count of number of command line arguments
    362: .  args - the command line arguments
    363: .  file - [optional] PETSc database file, defaults to ~username/.petscrc
    364:           (use NULL for default)
    365: -  help - [optional] Help message to print, use NULL for no message

    367:    Level: advanced

    369: .seealso: SlepcInitialize()
    370: @*/
    371: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *file,const char *help)
    372: {
    373:   int            myargc = argc;
    374:   char           **myargs = args;

    376:   SlepcInitialize(&myargc,&myargs,file,help);
    377:   PetscPopSignalHandler();
    378:   PetscBeganMPI = PETSC_FALSE;
    379:   return 0;
    380: }