Actual source code: slepcinit.c

slepc-3.11.2 2019-07-30
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2019, 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>           /*I "slepcsys.h" I*/

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

 16:     Not collective

 18:     Input Parameter:
 19: .   len - length of the string

 21:     Output Parameter:
 22: .   version - version string

 24:     Level: developer

 26: .seealso: SlepcGetVersionNumber()
 27: @*/
 28: PetscErrorCode SlepcGetVersion(char version[],size_t len)
 29: {

 33: #if (SLEPC_VERSION_RELEASE == 1)
 34:   PetscSNPrintf(version,len,"SLEPc Release Version %d.%d.%d, %s",SLEPC_VERSION_MAJOR,SLEPC_VERSION_MINOR,SLEPC_VERSION_SUBMINOR,SLEPC_VERSION_DATE);
 35: #else
 36:   PetscSNPrintf(version,len,"SLEPc Development GIT revision: %s  GIT Date: %s",SLEPC_VERSION_GIT,SLEPC_VERSION_DATE_GIT);
 37: #endif
 38:   return(0);
 39: }

 41: /*@C
 42:     SlepcGetVersionNumber - Gets the SLEPc version information from the library.

 44:     Not collective

 46:     Output Parameters:
 47: +   major    - the major version
 48: .   minor    - the minor version
 49: .   subminor - the subminor version (patch number)
 50: -   release  - indicates the library is from a release

 52:     Notes:
 53:     Pass NULL in any argument that is not requested.

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

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

 61:     Level: developer

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

 74: /*
 75:    SlepcPrintVersion - Prints SLEPc version info.

 77:    Collective on MPI_Comm
 78: */
 79: static PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
 80: {
 82:   char           version[256];

 85:   SlepcGetVersion(version,256);
 86:   (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
 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 on MPI_Comm
 98: */
 99: static PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
100: {
101:   PetscErrorCode  ierr;

104:   (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
105:   (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
106:   (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
107:   return(0);
108: }

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;

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

125:   PetscStrcpy(libs,SLEPC_LIB_DIR);
126:   PetscStrcat(libs,"/libslepc");
127:   PetscStrcat(libs,name);
128:   PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);
129:   if (*found) {
130:     PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
131:   }
132:   return(0);
133: }
134: #endif

136: #if defined(PETSC_HAVE_THREADSAFETY)
137: SLEPC_EXTERN PetscErrorCode STInitializePackage(void);
138: SLEPC_EXTERN PetscErrorCode DSInitializePackage(void);
139: SLEPC_EXTERN PetscErrorCode FNInitializePackage(void);
140: SLEPC_EXTERN PetscErrorCode BVInitializePackage(void);
141: SLEPC_EXTERN PetscErrorCode RGInitializePackage(void);
142: SLEPC_EXTERN PetscErrorCode EPSInitializePackage(void);
143: SLEPC_EXTERN PetscErrorCode SVDInitializePackage(void);
144: SLEPC_EXTERN PetscErrorCode PEPInitializePackage(void);
145: SLEPC_EXTERN PetscErrorCode NEPInitializePackage(void);
146: SLEPC_EXTERN PetscErrorCode MFNInitializePackage(void);
147: SLEPC_EXTERN PetscErrorCode LMEInitializePackage(void);
148: #endif

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

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

190: #if defined(PETSC_HAVE_THREADSAFETY)
191:   STInitializePackage();
192:   DSInitializePackage();
193:   FNInitializePackage();
194:   BVInitializePackage();
195:   RGInitializePackage();
196:   EPSInitializePackage();
197:   SVDInitializePackage();
198:   PEPInitializePackage();
199:   NEPInitializePackage();
200:   MFNInitializePackage();
201:   LMEInitializePackage();
202: #endif
203:   return(0);
204: }

206: PetscErrorCode SlepcCitationsInitialize()
207: {

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

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

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

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

245:    Fortran Note:
246:    Fortran syntax is very similar to that of PetscInitialize()

248:    Level: beginner

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

258:   if (SlepcInitializeCalled) return(0);
259:   PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
260:   PetscInitialized(&flg);
261:   if (!flg) {
262:     PetscInitialize(argc,args,file,help);
263:     SlepcBeganPetsc = PETSC_TRUE;
264:   }

266:   SlepcCitationsInitialize();

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

271: #if defined(PETSC_HAVE_DRAND48)
272:   /* work-around for Cygwin drand48() initialization bug */
273:   srand48(0);
274: #endif

276:   SlepcInitializeCalled = PETSC_TRUE;
277:   PetscInfo(0,"SLEPc successfully started\n");
278:   return(0);
279: }

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

285:    Collective on PETSC_COMM_WORLD

287:    Level: beginner

289: .seealso: SlepcInitialize(), PetscFinalize()
290: @*/
291: PetscErrorCode SlepcFinalize(void)
292: {
293:   PetscErrorCode 0;

296:   PetscInfo(0,"SlepcFinalize() called\n");
297:   if (SlepcBeganPetsc) {
298:     PetscFinalize();
299:   }
300:   SlepcInitializeCalled = PETSC_FALSE;
301:   PetscFunctionReturn(ierr);
302: }

304: /*@C
305:    SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
306:    the command line arguments.

308:    Collective

310:    Level: advanced

312: .seealso: SlepcInitialize(), SlepcInitializeFortran()
313: @*/
314: PetscErrorCode SlepcInitializeNoArguments(void)
315: {
317:   int            argc = 0;
318:   char           **args = 0;

321:   SlepcInitialize(&argc,&args,NULL,NULL);
322:   PetscFunctionReturn(ierr);
323: }

325: /*@
326:    SlepcInitialized - Determine whether SLEPc is initialized.

328:    Level: beginner

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

340: PETSC_EXTERN PetscBool PetscBeganMPI;

342: /*
343:    SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
344:    to argc and args (analogue to PetscInitializeNoPointers).

346:    Collective

348:    Level: advanced

350: .seealso: SlepcInitialize()
351: */
352: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
353: {
355:   int            myargc = argc;
356:   char           **myargs = args;

359:   SlepcInitialize(&myargc,&myargs,filename,help);
360:   PetscPopSignalHandler();
361:   PetscBeganMPI = PETSC_FALSE;
362:   PetscFunctionReturn(ierr);
363: }