Actual source code: slepcinit.c
slepc-3.13.0 2020-03-31
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> /*I "slepcsys.h" I*/
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,"--------------------------------------------------------------------------\n");
93: (*PetscHelpPrintf)(comm,"%s\n",version);
94: (*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO);
95: (*PetscHelpPrintf)(comm,"See docs/manual.html for help.\n");
96: (*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR);
97: return(0);
98: }
100: /*
101: SlepcPrintHelpIntro - Prints introductory SLEPc help info.
103: Collective
104: */
105: static PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
106: {
107: PetscErrorCode ierr;
110: (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
111: (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
112: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
113: return(0);
114: }
116: /* ------------------------Nasty global variables -------------------------------*/
117: /*
118: Indicates whether SLEPc started PETSc, or whether it was
119: already started before SLEPc was initialized.
120: */
121: PetscBool SlepcBeganPetsc = PETSC_FALSE;
122: PetscBool SlepcInitializeCalled = 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: PetscStrcat(libs,"/libslepc");
133: PetscStrcat(libs,name);
134: PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);
135: if (*found) {
136: PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
137: }
138: return(0);
139: }
140: #endif
142: #if defined(PETSC_HAVE_THREADSAFETY)
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: {
162: #if (defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)) || defined(PETSC_HAVE_THREADSAFETY)
164: #endif
165: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
166: PetscBool found,preload;
167: #endif
170: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
171: preload = PETSC_FALSE;
172: PetscOptionsGetBool(NULL,NULL,"-dynamic_library_preload",&preload,NULL);
173: if (preload) {
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: }
194: #endif
196: #if defined(PETSC_HAVE_THREADSAFETY)
197: STInitializePackage();
198: DSInitializePackage();
199: FNInitializePackage();
200: BVInitializePackage();
201: RGInitializePackage();
202: EPSInitializePackage();
203: SVDInitializePackage();
204: PEPInitializePackage();
205: NEPInitializePackage();
206: MFNInitializePackage();
207: LMEInitializePackage();
208: #endif
210: #if defined(SLEPC_HAVE_HPDDM)
211: KSPRegister(KSPHPDDM,KSPCreate_HPDDM);
212: PCRegister(PCHPDDM,PCCreate_HPDDM);
213: #endif
214: return(0);
215: }
217: PetscErrorCode SlepcCitationsInitialize()
218: {
222: PetscCitationsRegister("@Article{slepc-toms,\n"
223: " author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
224: " title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
225: " journal = \"{ACM} Trans. Math. Software\",\n"
226: " volume = \"31\",\n"
227: " number = \"3\",\n"
228: " pages = \"351--362\",\n"
229: " year = \"2005,\"\n"
230: " doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
231: "}\n",NULL);
232: PetscCitationsRegister("@TechReport{slepc-manual,\n"
233: " author = \"J. E. Roman and C. Campos and E. Romero and A. Tomas\",\n"
234: " title = \"{SLEPc} Users Manual\",\n"
235: " number = \"DSIC-II/24/02 - Revision 3.13\",\n"
236: " institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
237: " year = \"2020\"\n"
238: "}\n",NULL);
239: return(0);
240: }
242: /*@C
243: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
244: PetscInitialize() if that has not been called yet, so this routine should
245: always be called near the beginning of your program.
247: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
249: Input Parameters:
250: + argc - count of number of command line arguments
251: . args - the command line arguments
252: . file - [optional] PETSc database file, defaults to ~username/.petscrc
253: (use NULL for default)
254: - help - [optional] Help message to print, use NULL for no message
256: Fortran Note:
257: Fortran syntax is very similar to that of PetscInitialize()
259: Level: beginner
261: .seealso: SlepcFinalize(), PetscInitialize()
262: @*/
263: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
264: {
266: PetscBool flg;
269: if (SlepcInitializeCalled) return(0);
270: PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
271: PetscInitialized(&flg);
272: if (!flg) {
273: PetscInitialize(argc,args,file,help);
274: SlepcBeganPetsc = PETSC_TRUE;
275: }
277: SlepcCitationsInitialize();
279: /* Load the dynamic libraries (on machines that support them), this registers all the solvers etc. */
280: SlepcInitialize_DynamicLibraries();
282: #if defined(PETSC_HAVE_DRAND48)
283: /* work-around for Cygwin drand48() initialization bug */
284: srand48(0);
285: #endif
287: SlepcInitializeCalled = PETSC_TRUE;
288: PetscInfo(0,"SLEPc successfully started\n");
289: return(0);
290: }
292: /*@C
293: SlepcFinalize - Checks for options to be called at the conclusion
294: of the SLEPc program and calls PetscFinalize().
296: Collective on PETSC_COMM_WORLD
298: Level: beginner
300: .seealso: SlepcInitialize(), PetscFinalize()
301: @*/
302: PetscErrorCode SlepcFinalize(void)
303: {
304: PetscErrorCode 0;
307: PetscInfo(0,"SlepcFinalize() called\n");
308: if (SlepcBeganPetsc) {
309: PetscFinalize();
310: }
311: SlepcInitializeCalled = PETSC_FALSE;
312: PetscFunctionReturn(ierr);
313: }
315: /*@C
316: SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
317: the command line arguments.
319: Collective
321: Level: advanced
323: .seealso: SlepcInitialize(), SlepcInitializeFortran()
324: @*/
325: PetscErrorCode SlepcInitializeNoArguments(void)
326: {
328: int argc = 0;
329: char **args = 0;
332: SlepcInitialize(&argc,&args,NULL,NULL);
333: PetscFunctionReturn(ierr);
334: }
336: /*@
337: SlepcInitialized - Determine whether SLEPc is initialized.
339: Level: beginner
341: .seealso: SlepcInitialize(), SlepcInitializeFortran()
342: @*/
343: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
344: {
347: *isInitialized = SlepcInitializeCalled;
348: return(0);
349: }
351: PETSC_EXTERN PetscBool PetscBeganMPI;
353: /*
354: SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
355: to argc and args (analogue to PetscInitializeNoPointers).
357: Collective
359: Level: advanced
361: .seealso: SlepcInitialize()
362: */
363: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
364: {
366: int myargc = argc;
367: char **myargs = args;
370: SlepcInitialize(&myargc,&myargs,filename,help);
371: PetscPopSignalHandler();
372: PetscBeganMPI = PETSC_FALSE;
373: PetscFunctionReturn(ierr);
374: }