Actual source code: slepcinit.c
slepc-3.6.0 2015-06-12
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2015, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
8: SLEPc is free software: you can redistribute it and/or modify it under the
9: terms of version 3 of the GNU Lesser General Public License as published by
10: the Free Software Foundation.
12: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
13: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15: more details.
17: You should have received a copy of the GNU Lesser General Public License
18: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20: */
22: #include <slepc/private/slepcimpl.h> /*I "slepcsys.h" I*/
23: #include <slepc/private/vecimplslepc.h>
27: /*@C
28: SlepcGetVersion - Gets the SLEPc version information in a string.
30: Input Parameter:
31: . len - length of the string
33: Output Parameter:
34: . version - version string
36: Fortran Note:
37: This routine is not supported in Fortran.
39: Level: intermediate
40: @*/
41: PetscErrorCode SlepcGetVersion(char version[],size_t len)
42: {
46: #if (SLEPC_VERSION_RELEASE == 1)
47: PetscSNPrintf(version,len,"SLEPc Release Version %d.%d.%d, %s",SLEPC_VERSION_MAJOR,SLEPC_VERSION_MINOR,SLEPC_VERSION_SUBMINOR,SLEPC_VERSION_DATE);
48: #else
49: PetscSNPrintf(version,len,"SLEPc Development GIT revision: %d GIT Date: %s",SLEPC_VERSION_GIT,SLEPC_VERSION_DATE_GIT);
50: #endif
51: return(0);
52: }
56: /*
57: SlepcPrintVersion - Prints SLEPc version info.
59: Collective on MPI_Comm
60: */
61: static PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
62: {
64: char version[256];
67: SlepcGetVersion(version,256);
68: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
69: (*PetscHelpPrintf)(comm,"%s\n",version);
70: (*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO);
71: (*PetscHelpPrintf)(comm,"See docs/manual.html for help.\n");
72: (*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR);
73: return(0);
74: }
78: /*
79: SlepcPrintHelpIntro - Prints introductory SLEPc help info.
81: Collective on MPI_Comm
82: */
83: static PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
84: {
85: PetscErrorCode ierr;
88: (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
89: (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
90: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
91: return(0);
92: }
94: /* ------------------------Nasty global variables -------------------------------*/
95: /*
96: Indicates whether SLEPc started PETSc, or whether it was
97: already started before SLEPc was initialized.
98: */
99: PetscBool SlepcBeganPetsc = PETSC_FALSE;
100: PetscBool SlepcInitializeCalled = PETSC_FALSE;
102: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
106: static PetscErrorCode SlepcLoadDynamicLibrary(const char *name,PetscBool *found)
107: {
108: char libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
112: PetscStrcpy(libs,SLEPC_LIB_DIR);
113: PetscStrcat(libs,"/libslepc");
114: PetscStrcat(libs,name);
115: PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);
116: if (*found) {
117: PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);
118: }
119: return(0);
120: }
124: /*
125: SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
126: search path.
127: */
128: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
129: {
131: PetscBool found;
132: PetscBool preload;
135: preload = PETSC_FALSE;
136: PetscOptionsGetBool(NULL,"-dynamic_library_preload",&preload,NULL);
137: if (preload) {
138: #if defined(PETSC_USE_SINGLE_LIBRARY)
139: SlepcLoadDynamicLibrary("",&found);
140: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
141: #else
142: SlepcLoadDynamicLibrary("sys",&found);
143: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
144: SlepcLoadDynamicLibrary("eps",&found);
145: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
146: SlepcLoadDynamicLibrary("pep",&found);
147: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
148: SlepcLoadDynamicLibrary("nep",&found);
149: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
150: SlepcLoadDynamicLibrary("svd",&found);
151: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
152: SlepcLoadDynamicLibrary("mfn",&found);
153: if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!");
154: #endif
155: }
157: #if defined(PETSC_HAVE_THREADSAFETY)
158: STInitializePackage();
159: DSInitializePackage();
160: FNInitializePackage();
161: BVInitializePackage();
162: RGInitializePackage();
163: EPSInitializePackage();
164: SVDInitializePackage();
165: PEPInitializePackage();
166: NEPInitializePackage();
167: MFNInitializePackage();
168: #endif
169: return(0);
170: }
171: #endif
175: /*@C
176: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
177: PetscInitialize() if that has not been called yet, so this routine should
178: always be called near the beginning of your program.
180: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
182: Input Parameters:
183: + argc - count of number of command line arguments
184: . args - the command line arguments
185: . file - [optional] PETSc database file, defaults to ~username/.petscrc
186: (use NULL for default)
187: - help - [optional] Help message to print, use NULL for no message
189: Fortran Note:
190: Fortran syntax is very similar to that of PetscInitialize()
192: Level: beginner
194: .seealso: SlepcFinalize(), PetscInitialize()
195: @*/
196: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
197: {
199: PetscBool flg;
202: if (SlepcInitializeCalled) return(0);
203: PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
204: PetscInitialized(&flg);
205: if (!flg) {
206: PetscInitialize(argc,args,file,help);
207: SlepcBeganPetsc = PETSC_TRUE;
208: }
210: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
211: SlepcInitialize_DynamicLibraries();
212: #endif
214: #if defined(PETSC_HAVE_DRAND48)
215: /* work-around for Cygwin drand48() initialization bug */
216: srand48(0);
217: #endif
219: SlepcInitializeCalled = PETSC_TRUE;
220: PetscInfo(0,"SLEPc successfully started\n");
221: return(0);
222: }
226: /*@
227: SlepcFinalize - Checks for options to be called at the conclusion
228: of the SLEPc program and calls PetscFinalize().
230: Collective on PETSC_COMM_WORLD
232: Level: beginner
234: .seealso: SlepcInitialize(), PetscFinalize()
235: @*/
236: PetscErrorCode SlepcFinalize(void)
237: {
241: PetscInfo(0,"SlepcFinalize() called\n");
242: if (SlepcBeganPetsc) {
243: PetscFinalize();
244: }
245: SlepcInitializeCalled = PETSC_FALSE;
246: return(0);
247: }
251: /*@C
252: SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
253: the command line arguments.
255: Collective
257: Level: advanced
259: .seealso: SlepcInitialize(), SlepcInitializeFortran()
260: @*/
261: PetscErrorCode SlepcInitializeNoArguments(void)
262: {
264: int argc = 0;
265: char **args = 0;
268: SlepcInitialize(&argc,&args,NULL,NULL);
269: PetscFunctionReturn(ierr);
270: }
274: /*@
275: SlepcInitialized - Determine whether SLEPc is initialized.
277: Level: beginner
279: .seealso: SlepcInitialize(), SlepcInitializeFortran()
280: @*/
281: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
282: {
285: *isInitialized = SlepcInitializeCalled;
286: return(0);
287: }
289: PETSC_EXTERN PetscBool PetscBeganMPI;
293: /*
294: SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
295: to argc and args (analogue to PetscInitializeNoPointers).
297: Collective
299: Level: advanced
301: .seealso: SlepcInitialize()
302: */
303: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
304: {
306: int myargc = argc;
307: char **myargs = args;
310: SlepcInitialize(&myargc,&myargs,filename,help);
311: PetscPopSignalHandler();
312: PetscBeganMPI = PETSC_FALSE;
313: PetscFunctionReturn(ierr);
314: }