Actual source code: slepcinit.c

slepc-3.13.2 2020-05-12
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2020, 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: developer

 32: .seealso: SlepcGetVersionNumber()
 33: @*/
 34: PetscErrorCode SlepcGetVersion(char version[],size_t len)
 35: {

 39: #if (SLEPC_VERSION_RELEASE == 1)
 40:   PetscSNPrintf(version,len,"SLEPc Release Version %d.%d.%d, %s",SLEPC_VERSION_MAJOR,SLEPC_VERSION_MINOR,SLEPC_VERSION_SUBMINOR,SLEPC_VERSION_DATE);
 41: #else
 42:   PetscSNPrintf(version,len,"SLEPc Development GIT revision: %s  GIT Date: %s",SLEPC_VERSION_GIT,SLEPC_VERSION_DATE_GIT);
 43: #endif
 44:   return(0);
 45: }

 47: /*@C
 48:     SlepcGetVersionNumber - Gets the SLEPc version information from the library.

 50:     Not collective

 52:     Output Parameters:
 53: +   major    - the major version
 54: .   minor    - the minor version
 55: .   subminor - the subminor version (patch number)
 56: -   release  - indicates the library is from a release

 58:     Notes:
 59:     Pass NULL in any argument that is not requested.

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

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

 67:     Level: developer

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

 80: /*
 81:    SlepcPrintVersion - Prints SLEPc version info.

 83:    Collective
 84: */
 85: static PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
 86: {
 88:   char           version[256];

 91:   SlepcGetVersion(version,256);
 92:   (*PetscHelpPrintf)(comm,"%s\n",version);
 93:   (*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO);
 94:   (*PetscHelpPrintf)(comm,"See docs/manual.html for help.\n");
 95:   (*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR);
 96:   return(0);
 97: }

 99: /*
100:    SlepcPrintHelpIntro - Prints introductory SLEPc help info.

102:    Collective
103: */
104: static PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
105: {
106:   PetscErrorCode  ierr;

109:   (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
110:   (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
111:   (*PetscHelpPrintf)(comm,"----------------------------------------\n");
112:   return(0);
113: }

115: /* ------------------------Nasty global variables -------------------------------*/
116: /*
117:    Indicates whether SLEPc started PETSc, or whether it was
118:    already started before SLEPc was initialized.
119: */
120: PetscBool SlepcBeganPetsc = PETSC_FALSE;
121: PetscBool SlepcInitializeCalled = PETSC_FALSE;

123: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
124: static PetscErrorCode SlepcLoadDynamicLibrary(const char *name,PetscBool *found)
125: {
126:   char           libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];

130:   PetscStrcpy(libs,SLEPC_LIB_DIR);
131:   PetscStrcat(libs,"/libslepc");
132:   PetscStrcat(libs,name);
133:   PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);
134:   if (*found) {
135:     PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
136:   }
137:   return(0);
138: }
139: #endif

141: #if defined(PETSC_HAVE_THREADSAFETY)
142: SLEPC_EXTERN PetscErrorCode STInitializePackage(void);
143: SLEPC_EXTERN PetscErrorCode DSInitializePackage(void);
144: SLEPC_EXTERN PetscErrorCode FNInitializePackage(void);
145: SLEPC_EXTERN PetscErrorCode BVInitializePackage(void);
146: SLEPC_EXTERN PetscErrorCode RGInitializePackage(void);
147: SLEPC_EXTERN PetscErrorCode EPSInitializePackage(void);
148: SLEPC_EXTERN PetscErrorCode SVDInitializePackage(void);
149: SLEPC_EXTERN PetscErrorCode PEPInitializePackage(void);
150: SLEPC_EXTERN PetscErrorCode NEPInitializePackage(void);
151: SLEPC_EXTERN PetscErrorCode MFNInitializePackage(void);
152: SLEPC_EXTERN PetscErrorCode LMEInitializePackage(void);
153: #endif

155: /*
156:     SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
157:     search path.
158: */
159: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
160: {
161: #if (defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)) || defined(PETSC_HAVE_THREADSAFETY)
163: #endif
164: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
165:   PetscBool      found,preload;
166: #endif

169: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
170:   preload = PETSC_FALSE;
171:   PetscOptionsGetBool(NULL,NULL,"-dynamic_library_preload",&preload,NULL);
172:   if (preload) {
173: #if defined(PETSC_USE_SINGLE_LIBRARY)
174:     SlepcLoadDynamicLibrary("",&found);
175:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
176: #else
177:     SlepcLoadDynamicLibrary("sys",&found);
178:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc sys dynamic library\nYou cannot move the dynamic libraries!");
179:     SlepcLoadDynamicLibrary("eps",&found);
180:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc EPS dynamic library\nYou cannot move the dynamic libraries!");
181:     SlepcLoadDynamicLibrary("pep",&found);
182:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc PEP dynamic library\nYou cannot move the dynamic libraries!");
183:     SlepcLoadDynamicLibrary("nep",&found);
184:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc NEP dynamic library\nYou cannot move the dynamic libraries!");
185:     SlepcLoadDynamicLibrary("svd",&found);
186:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc SVD dynamic library\nYou cannot move the dynamic libraries!");
187:     SlepcLoadDynamicLibrary("mfn",&found);
188:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc MFN dynamic library\nYou cannot move the dynamic libraries!");
189:     SlepcLoadDynamicLibrary("lme",&found);
190:     if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc LME dynamic library\nYou cannot move the dynamic libraries!");
191: #endif
192:   }
193: #endif

195: #if defined(PETSC_HAVE_THREADSAFETY)
196:   STInitializePackage();
197:   DSInitializePackage();
198:   FNInitializePackage();
199:   BVInitializePackage();
200:   RGInitializePackage();
201:   EPSInitializePackage();
202:   SVDInitializePackage();
203:   PEPInitializePackage();
204:   NEPInitializePackage();
205:   MFNInitializePackage();
206:   LMEInitializePackage();
207: #endif

209: #if defined(SLEPC_HAVE_HPDDM)
210:   KSPRegister(KSPHPDDM,KSPCreate_HPDDM);
211:   PCRegister(PCHPDDM,PCCreate_HPDDM);
212: #endif
213:   return(0);
214: }

216: PetscErrorCode SlepcCitationsInitialize()
217: {

221:   PetscCitationsRegister("@Article{slepc-toms,\n"
222:     "   author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
223:     "   title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
224:     "   journal = \"{ACM} Trans. Math. Software\",\n"
225:     "   volume = \"31\",\n"
226:     "   number = \"3\",\n"
227:     "   pages = \"351--362\",\n"
228:     "   year = \"2005,\"\n"
229:     "   doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
230:     "}\n",NULL);
231:   PetscCitationsRegister("@TechReport{slepc-manual,\n"
232:     "   author = \"J. E. Roman and C. Campos and E. Romero and A. Tomas\",\n"
233:     "   title = \"{SLEPc} Users Manual\",\n"
234:     "   number = \"DSIC-II/24/02 - Revision 3.13\",\n"
235:     "   institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
236:     "   year = \"2020\"\n"
237:     "}\n",NULL);
238:   return(0);
239: }

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

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

248:    Input Parameters:
249: +  argc - count of number of command line arguments
250: .  args - the command line arguments
251: .  file - [optional] PETSc database file, defaults to ~username/.petscrc
252:           (use NULL for default)
253: -  help - [optional] Help message to print, use NULL for no message

255:    Fortran Note:
256:    Fortran syntax is very similar to that of PetscInitialize()

258:    Level: beginner

260: .seealso: SlepcFinalize(), PetscInitialize()
261: @*/
262: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
263: {
265:   PetscBool      flg;

268:   if (SlepcInitializeCalled) return(0);
269:   PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
270:   PetscInitialized(&flg);
271:   if (!flg) {
272:     PetscInitialize(argc,args,file,help);
273:     SlepcBeganPetsc = PETSC_TRUE;
274:   }

276:   SlepcCitationsInitialize();

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

281: #if defined(PETSC_HAVE_DRAND48)
282:   /* work-around for Cygwin drand48() initialization bug */
283:   srand48(0);
284: #endif

286:   SlepcInitializeCalled = PETSC_TRUE;
287:   PetscInfo(0,"SLEPc successfully started\n");
288:   return(0);
289: }

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

295:    Collective on PETSC_COMM_WORLD

297:    Level: beginner

299: .seealso: SlepcInitialize(), PetscFinalize()
300: @*/
301: PetscErrorCode SlepcFinalize(void)
302: {
303:   PetscErrorCode 0;

306:   PetscInfo(0,"SlepcFinalize() called\n");
307:   if (SlepcBeganPetsc) {
308:     PetscFinalize();
309:   }
310:   SlepcInitializeCalled = PETSC_FALSE;
311:   PetscFunctionReturn(ierr);
312: }

314: /*@C
315:    SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
316:    the command line arguments.

318:    Collective

320:    Level: advanced

322: .seealso: SlepcInitialize(), SlepcInitializeFortran()
323: @*/
324: PetscErrorCode SlepcInitializeNoArguments(void)
325: {
327:   int            argc = 0;
328:   char           **args = 0;

331:   SlepcInitialize(&argc,&args,NULL,NULL);
332:   PetscFunctionReturn(ierr);
333: }

335: /*@
336:    SlepcInitialized - Determine whether SLEPc is initialized.

338:    Level: beginner

340: .seealso: SlepcInitialize(), SlepcInitializeFortran()
341: @*/
342: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
343: {
346:   *isInitialized = SlepcInitializeCalled;
347:   return(0);
348: }

350: PETSC_EXTERN PetscBool PetscBeganMPI;

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

356:    Collective

358:    Level: advanced

360: .seealso: SlepcInitialize()
361: */
362: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
363: {
365:   int            myargc = argc;
366:   char           **myargs = args;

369:   SlepcInitialize(&myargc,&myargs,filename,help);
370:   PetscPopSignalHandler();
371:   PetscBeganMPI = PETSC_FALSE;
372:   PetscFunctionReturn(ierr);
373: }