Actual source code: slepcinit.c
slepc-3.15.0 2021-03-31
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: 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: PetscStrlcat(libs,"/libslepc",sizeof(libs));
132: PetscStrlcat(libs,name,sizeof(libs));
133: PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,sizeof(dlib),found);
134: if (*found) {
135: PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
136: }
137: return(0);
138: }
139: #endif
141: #if defined(PETSC_USE_SINGLE_LIBRARY) && !(defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES))
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: {
162: PetscBool preload = PETSC_FALSE;
165: #if defined(PETSC_HAVE_THREADSAFETY)
166: /* These must be all initialized here because it is not safe for individual threads to call these initialize routines */
167: preload = PETSC_TRUE;
168: #endif
170: PetscOptionsGetBool(NULL,NULL,"-library_preload",&preload,NULL);
171: if (preload) {
172: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
173: PetscBool found;
174: #if defined(PETSC_USE_SINGLE_LIBRARY)
175: SlepcLoadDynamicLibrary("",&found);
176: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
177: #else
178: SlepcLoadDynamicLibrary("sys",&found);
179: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc sys dynamic library\nYou cannot move the dynamic libraries!");
180: SlepcLoadDynamicLibrary("eps",&found);
181: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc EPS dynamic library\nYou cannot move the dynamic libraries!");
182: SlepcLoadDynamicLibrary("pep",&found);
183: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc PEP dynamic library\nYou cannot move the dynamic libraries!");
184: SlepcLoadDynamicLibrary("nep",&found);
185: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc NEP dynamic library\nYou cannot move the dynamic libraries!");
186: SlepcLoadDynamicLibrary("svd",&found);
187: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc SVD dynamic library\nYou cannot move the dynamic libraries!");
188: SlepcLoadDynamicLibrary("mfn",&found);
189: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc MFN dynamic library\nYou cannot move the dynamic libraries!");
190: SlepcLoadDynamicLibrary("lme",&found);
191: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc LME dynamic library\nYou cannot move the dynamic libraries!");
192: #endif
193: #else /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
194: #if defined(PETSC_USE_SINGLE_LIBRARY)
195: STInitializePackage();
196: DSInitializePackage();
197: FNInitializePackage();
198: BVInitializePackage();
199: RGInitializePackage();
200: EPSInitializePackage();
201: SVDInitializePackage();
202: PEPInitializePackage();
203: NEPInitializePackage();
204: MFNInitializePackage();
205: LMEInitializePackage();
206: #else
207: SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Cannot use -library_preload with multiple static SLEPc libraries");
208: #endif
209: #endif /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */
210: }
212: #if defined(SLEPC_HAVE_HPDDM)
213: KSPRegister(KSPHPDDM,KSPCreate_HPDDM);
214: PCRegister(PCHPDDM,PCCreate_HPDDM);
215: #endif
216: return(0);
217: }
219: PetscErrorCode SlepcCitationsInitialize()
220: {
224: PetscCitationsRegister("@Article{slepc-toms,\n"
225: " author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
226: " title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
227: " journal = \"{ACM} Trans. Math. Software\",\n"
228: " volume = \"31\",\n"
229: " number = \"3\",\n"
230: " pages = \"351--362\",\n"
231: " year = \"2005,\"\n"
232: " doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
233: "}\n",NULL);
234: PetscCitationsRegister("@TechReport{slepc-manual,\n"
235: " author = \"J. E. Roman and C. Campos and L. Dalcin and E. Romero and A. Tomas\",\n"
236: " title = \"{SLEPc} Users Manual\",\n"
237: " number = \"DSIC-II/24/02 - Revision 3.15\",\n"
238: " institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
239: " year = \"2021\"\n"
240: "}\n",NULL);
241: return(0);
242: }
244: /*@C
245: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
246: PetscInitialize() if that has not been called yet, so this routine should
247: always be called near the beginning of your program.
249: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
251: Input Parameters:
252: + argc - count of number of command line arguments
253: . args - the command line arguments
254: . file - [optional] PETSc database file, defaults to ~username/.petscrc
255: (use NULL for default)
256: - help - [optional] Help message to print, use NULL for no message
258: Fortran Note:
259: Fortran syntax is very similar to that of PetscInitialize()
261: Level: beginner
263: .seealso: SlepcFinalize(), PetscInitialize()
264: @*/
265: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
266: {
268: PetscBool flg;
271: if (SlepcInitializeCalled) return(0);
272: PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
273: PetscInitialized(&flg);
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: PetscInfo(0,"SLEPc successfully started\n");
286: return(0);
287: }
289: /*@C
290: SlepcFinalize - Checks for options to be called at the conclusion
291: of the SLEPc program and calls PetscFinalize().
293: Collective on PETSC_COMM_WORLD
295: Level: beginner
297: .seealso: SlepcInitialize(), PetscFinalize()
298: @*/
299: PetscErrorCode SlepcFinalize(void)
300: {
301: PetscErrorCode 0;
304: PetscInfo(0,"SlepcFinalize() called\n");
305: if (SlepcBeganPetsc) {
306: PetscFinalize();
307: }
308: SlepcInitializeCalled = PETSC_FALSE;
309: PetscFunctionReturn(ierr);
310: }
312: /*@C
313: SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
314: the command line arguments.
316: Collective
318: Level: advanced
320: .seealso: SlepcInitialize(), SlepcInitializeFortran()
321: @*/
322: PetscErrorCode SlepcInitializeNoArguments(void)
323: {
325: int argc = 0;
326: char **args = 0;
329: SlepcInitialize(&argc,&args,NULL,NULL);
330: PetscFunctionReturn(ierr);
331: }
333: /*@
334: SlepcInitialized - Determine whether SLEPc is initialized.
336: Level: beginner
338: .seealso: SlepcInitialize(), SlepcInitializeFortran()
339: @*/
340: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
341: {
344: *isInitialized = SlepcInitializeCalled;
345: return(0);
346: }
348: PETSC_EXTERN PetscBool PetscBeganMPI;
350: /*
351: SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
352: to argc and args (analogue to PetscInitializeNoPointers).
354: Collective
356: Level: advanced
358: .seealso: SlepcInitialize()
359: */
360: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
361: {
363: int myargc = argc;
364: char **myargs = args;
367: SlepcInitialize(&myargc,&myargs,filename,help);
368: PetscPopSignalHandler();
369: PetscBeganMPI = PETSC_FALSE;
370: PetscFunctionReturn(ierr);
371: }