Actual source code: slepcinit.c
slepc-3.10.1 2018-10-23
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2018, 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: /*
137: SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
138: search path.
139: */
140: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
141: {
142: #if (defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)) || defined(PETSC_HAVE_THREADSAFETY)
144: #endif
145: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
146: PetscBool found,preload;
147: #endif
150: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
151: preload = PETSC_FALSE;
152: PetscOptionsGetBool(NULL,NULL,"-dynamic_library_preload",&preload,NULL);
153: if (preload) {
154: #if defined(PETSC_USE_SINGLE_LIBRARY)
155: SlepcLoadDynamicLibrary("",&found);
156: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
157: #else
158: SlepcLoadDynamicLibrary("sys",&found);
159: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc sys dynamic library\nYou cannot move the dynamic libraries!");
160: SlepcLoadDynamicLibrary("eps",&found);
161: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc EPS dynamic library\nYou cannot move the dynamic libraries!");
162: SlepcLoadDynamicLibrary("pep",&found);
163: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc PEP dynamic library\nYou cannot move the dynamic libraries!");
164: SlepcLoadDynamicLibrary("nep",&found);
165: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc NEP dynamic library\nYou cannot move the dynamic libraries!");
166: SlepcLoadDynamicLibrary("svd",&found);
167: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc SVD dynamic library\nYou cannot move the dynamic libraries!");
168: SlepcLoadDynamicLibrary("mfn",&found);
169: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc MFN dynamic library\nYou cannot move the dynamic libraries!");
170: SlepcLoadDynamicLibrary("lme",&found);
171: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc LME dynamic library\nYou cannot move the dynamic libraries!");
172: #endif
173: }
174: #endif
176: #if defined(PETSC_HAVE_THREADSAFETY)
177: STInitializePackage();
178: DSInitializePackage();
179: FNInitializePackage();
180: BVInitializePackage();
181: RGInitializePackage();
182: EPSInitializePackage();
183: SVDInitializePackage();
184: PEPInitializePackage();
185: NEPInitializePackage();
186: MFNInitializePackage();
187: LMEInitializePackage();
188: #endif
189: return(0);
190: }
192: PetscErrorCode SlepcCitationsInitialize()
193: {
197: PetscCitationsRegister("@Article{slepc-toms,\n"
198: " author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
199: " title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
200: " journal = \"{ACM} Trans. Math. Software\",\n"
201: " volume = \"31\",\n"
202: " number = \"3\",\n"
203: " pages = \"351--362\",\n"
204: " year = \"2005,\"\n"
205: " doi = \"https://doi.org/10.1145/1089014.1089019\"\n"
206: "}\n",NULL);
207: PetscCitationsRegister("@TechReport{slepc-manual,\n"
208: " author = \"J. E. Roman and C. Campos and E. Romero and A. Tomas\",\n"
209: " title = \"{SLEPc} Users Manual\",\n"
210: " number = \"DSIC-II/24/02 - Revision 3.10\",\n"
211: " institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
212: " year = \"2018\"\n"
213: "}\n",NULL);
214: return(0);
215: }
217: /*@C
218: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
219: PetscInitialize() if that has not been called yet, so this routine should
220: always be called near the beginning of your program.
222: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
224: Input Parameters:
225: + argc - count of number of command line arguments
226: . args - the command line arguments
227: . file - [optional] PETSc database file, defaults to ~username/.petscrc
228: (use NULL for default)
229: - help - [optional] Help message to print, use NULL for no message
231: Fortran Note:
232: Fortran syntax is very similar to that of PetscInitialize()
234: Level: beginner
236: .seealso: SlepcFinalize(), PetscInitialize()
237: @*/
238: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
239: {
241: PetscBool flg;
244: if (SlepcInitializeCalled) return(0);
245: PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
246: PetscInitialized(&flg);
247: if (!flg) {
248: PetscInitialize(argc,args,file,help);
249: SlepcBeganPetsc = PETSC_TRUE;
250: }
252: SlepcCitationsInitialize();
254: /* Load the dynamic libraries (on machines that support them), this registers all the solvers etc. */
255: SlepcInitialize_DynamicLibraries();
257: #if defined(PETSC_HAVE_DRAND48)
258: /* work-around for Cygwin drand48() initialization bug */
259: srand48(0);
260: #endif
262: SlepcInitializeCalled = PETSC_TRUE;
263: PetscInfo(0,"SLEPc successfully started\n");
264: return(0);
265: }
267: /*@C
268: SlepcFinalize - Checks for options to be called at the conclusion
269: of the SLEPc program and calls PetscFinalize().
271: Collective on PETSC_COMM_WORLD
273: Level: beginner
275: .seealso: SlepcInitialize(), PetscFinalize()
276: @*/
277: PetscErrorCode SlepcFinalize(void)
278: {
279: PetscErrorCode 0;
282: PetscInfo(0,"SlepcFinalize() called\n");
283: if (SlepcBeganPetsc) {
284: PetscFinalize();
285: }
286: SlepcInitializeCalled = PETSC_FALSE;
287: PetscFunctionReturn(ierr);
288: }
290: /*@C
291: SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
292: the command line arguments.
294: Collective
296: Level: advanced
298: .seealso: SlepcInitialize(), SlepcInitializeFortran()
299: @*/
300: PetscErrorCode SlepcInitializeNoArguments(void)
301: {
303: int argc = 0;
304: char **args = 0;
307: SlepcInitialize(&argc,&args,NULL,NULL);
308: PetscFunctionReturn(ierr);
309: }
311: /*@
312: SlepcInitialized - Determine whether SLEPc is initialized.
314: Level: beginner
316: .seealso: SlepcInitialize(), SlepcInitializeFortran()
317: @*/
318: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
319: {
322: *isInitialized = SlepcInitializeCalled;
323: return(0);
324: }
326: PETSC_EXTERN PetscBool PetscBeganMPI;
328: /*
329: SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
330: to argc and args (analogue to PetscInitializeNoPointers).
332: Collective
334: Level: advanced
336: .seealso: SlepcInitialize()
337: */
338: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
339: {
341: int myargc = argc;
342: char **myargs = args;
345: SlepcInitialize(&myargc,&myargs,filename,help);
346: PetscPopSignalHandler();
347: PetscBeganMPI = PETSC_FALSE;
348: PetscFunctionReturn(ierr);
349: }