Actual source code: slepcinit.c
slepc-3.16.2 2022-02-01
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2021, 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: {
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: intermediate
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;
122: PetscBool SlepcFinalizeCalled = PETSC_FALSE;
124: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
125: static PetscErrorCode SlepcLoadDynamicLibrary(const char *name,PetscBool *found)
126: {
127: char libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
131: PetscStrcpy(libs,SLEPC_LIB_DIR);
132: PetscStrlcat(libs,"/libslepc",sizeof(libs));
133: PetscStrlcat(libs,name,sizeof(libs));
134: PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,sizeof(dlib),found);
135: if (*found) {
136: PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
137: }
138: return(0);
139: }
140: #endif
142: #if defined(PETSC_USE_SINGLE_LIBRARY) && !(defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES))
143: SLEPC_EXTERN PetscErrorCode STInitializePackage(void);
144: SLEPC_EXTERN PetscErrorCode DSInitializePackage(void);
145: SLEPC_EXTERN PetscErrorCode FNInitializePackage(void);
146: SLEPC_EXTERN PetscErrorCode BVInitializePackage(void);
147: SLEPC_EXTERN PetscErrorCode RGInitializePackage(void);
148: SLEPC_EXTERN PetscErrorCode EPSInitializePackage(void);
149: SLEPC_EXTERN PetscErrorCode SVDInitializePackage(void);
150: SLEPC_EXTERN PetscErrorCode PEPInitializePackage(void);
151: SLEPC_EXTERN PetscErrorCode NEPInitializePackage(void);
152: SLEPC_EXTERN PetscErrorCode MFNInitializePackage(void);
153: SLEPC_EXTERN PetscErrorCode LMEInitializePackage(void);
154: #endif
156: /*
157: SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
158: search path.
159: */
160: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
161: {
163: PetscBool preload = PETSC_FALSE;
166: #if defined(PETSC_HAVE_THREADSAFETY)
167: /* These must be all initialized here because it is not safe for individual threads to call these initialize routines */
168: preload = PETSC_TRUE;
169: #endif
171: PetscOptionsGetBool(NULL,NULL,"-library_preload",&preload,NULL);
172: if (preload) {
173: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
174: PetscBool found;
175: #if defined(PETSC_USE_SINGLE_LIBRARY)
176: SlepcLoadDynamicLibrary("",&found);
177: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
178: #else
179: SlepcLoadDynamicLibrary("sys",&found);
180: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc sys dynamic library\nYou cannot move the dynamic libraries!");
181: SlepcLoadDynamicLibrary("eps",&found);
182: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc EPS dynamic library\nYou cannot move the dynamic libraries!");
183: SlepcLoadDynamicLibrary("pep",&found);
184: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc PEP dynamic library\nYou cannot move the dynamic libraries!");
185: SlepcLoadDynamicLibrary("nep",&found);
186: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc NEP dynamic library\nYou cannot move the dynamic libraries!");
187: SlepcLoadDynamicLibrary("svd",&found);
188: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc SVD dynamic library\nYou cannot move the dynamic libraries!");
189: SlepcLoadDynamicLibrary("mfn",&found);
190: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc MFN dynamic library\nYou cannot move the dynamic libraries!");
191: SlepcLoadDynamicLibrary("lme",&found);
192: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc LME dynamic library\nYou cannot move the dynamic libraries!");
193: #endif
194: #else /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
195: #if defined(PETSC_USE_SINGLE_LIBRARY)
196: STInitializePackage();
197: DSInitializePackage();
198: FNInitializePackage();
199: BVInitializePackage();
200: RGInitializePackage();
201: EPSInitializePackage();
202: SVDInitializePackage();
203: PEPInitializePackage();
204: NEPInitializePackage();
205: MFNInitializePackage();
206: LMEInitializePackage();
207: #else
208: SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Cannot use -library_preload with multiple static SLEPc libraries");
209: #endif
210: #endif /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
211: }
213: #if defined(SLEPC_HAVE_HPDDM)
214: KSPRegister(KSPHPDDM,KSPCreate_HPDDM);
215: PCRegister(PCHPDDM,PCCreate_HPDDM);
216: #endif
217: return(0);
218: }
220: PetscErrorCode SlepcCitationsInitialize()
221: {
225: PetscCitationsRegister("@Article{slepc-toms,\n"
226: " author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
227: " title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
228: " journal = \"{ACM} Trans. Math. Software\",\n"
229: " volume = \"31\",\n"
230: " number = \"3\",\n"
231: " pages = \"351--362\",\n"
232: " year = \"2005,\"\n"
233: " doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
234: "}\n",NULL);
235: PetscCitationsRegister("@TechReport{slepc-manual,\n"
236: " author = \"J. E. Roman and C. Campos and L. Dalcin and E. Romero and A. Tomas\",\n"
237: " title = \"{SLEPc} Users Manual\",\n"
238: " number = \"DSIC-II/24/02 - Revision 3.16\",\n"
239: " institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
240: " year = \"2021\"\n"
241: "}\n",NULL);
242: return(0);
243: }
245: /*@C
246: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
247: PetscInitialize() if that has not been called yet, so this routine should
248: always be called near the beginning of your program.
250: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
252: Input Parameters:
253: + argc - count of number of command line arguments
254: . args - the command line arguments
255: . file - [optional] PETSc database file, defaults to ~username/.petscrc
256: (use NULL for default)
257: - help - [optional] Help message to print, use NULL for no message
259: Fortran Note:
260: Fortran syntax is very similar to that of PetscInitialize()
262: Level: beginner
264: .seealso: SlepcFinalize(), PetscInitialize()
265: @*/
266: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
267: {
269: PetscBool flg;
271: if (SlepcInitializeCalled) return 0;
272: PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);if (ierr) return ierr;
273: PetscInitialized(&flg);if (ierr) return ierr;
274: if (!flg) {
275: PetscInitialize(argc,args,file,help);
276: SlepcBeganPetsc = PETSC_TRUE;
277: }
279: SlepcCitationsInitialize();
281: /* Load the dynamic libraries (on machines that support them), this registers all the solvers etc. */
282: SlepcInitialize_DynamicLibraries();
284: SlepcInitializeCalled = PETSC_TRUE;
285: SlepcFinalizeCalled = PETSC_FALSE;
286: PetscInfo(0,"SLEPc successfully started\n");
287: return 0;
288: }
290: /*@C
291: SlepcFinalize - Checks for options to be called at the conclusion
292: of the SLEPc program and calls PetscFinalize().
294: Collective on PETSC_COMM_WORLD
296: Level: beginner
298: .seealso: SlepcInitialize(), PetscFinalize()
299: @*/
300: PetscErrorCode SlepcFinalize(void)
301: {
302: PetscErrorCode 0;
305: if (PetscUnlikely(!SlepcInitializeCalled)) {
306: fprintf(PETSC_STDOUT,"SlepcInitialize() must be called before SlepcFinalize()\n");
307: PetscStackClearTop;
308: return PETSC_ERR_ARG_WRONGSTATE;
309: }
310: PetscInfo(NULL,"SlepcFinalize() called\n");
311: if (SlepcBeganPetsc) {
312: PetscFinalize();
313: SlepcBeganPetsc = PETSC_FALSE;
314: }
315: SlepcInitializeCalled = PETSC_FALSE;
316: SlepcFinalizeCalled = PETSC_TRUE;
318: PetscStackClearTop;
319: return ierr;
320: }
322: /*@C
323: SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
324: the command line arguments.
326: Collective
328: Level: advanced
330: .seealso: SlepcInitialize(), SlepcInitializeFortran()
331: @*/
332: PetscErrorCode SlepcInitializeNoArguments(void)
333: {
335: int argc = 0;
336: char **args = 0;
339: SlepcInitialize(&argc,&args,NULL,NULL);
340: PetscFunctionReturn(ierr);
341: }
343: /*@
344: SlepcInitialized - Determine whether SLEPc is initialized.
346: Level: beginner
348: .seealso: SlepcInitialize(), SlepcInitializeFortran()
349: @*/
350: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
351: {
353: *isInitialized = SlepcInitializeCalled;
354: return(0);
355: }
357: /*@
358: SlepcFinalized - Determine whether SlepcFinalize() has been called.
360: Level: developer
362: .seealso: SlepcFinalize()
363: @*/
364: PetscErrorCode SlepcFinalized(PetscBool *isFinalized)
365: {
367: *isFinalized = SlepcFinalizeCalled;
368: return(0);
369: }
371: PETSC_EXTERN PetscBool PetscBeganMPI;
373: /*
374: SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
375: to argc and args (analogue to PetscInitializeNoPointers).
377: Collective
379: Level: advanced
381: .seealso: SlepcInitialize()
382: */
383: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
384: {
386: int myargc = argc;
387: char **myargs = args;
390: SlepcInitialize(&myargc,&myargs,filename,help);
391: PetscPopSignalHandler();
392: PetscBeganMPI = PETSC_FALSE;
393: return(0);
394: }