Actual source code: slepcinit.c
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2012, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7:
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/epsimpl.h>
24: #include <slepc-private/stimpl.h>
25: #include <slepc-private/svdimpl.h>
26: #include <slepc-private/qepimpl.h>
27: #include <slepc-private/ipimpl.h>
28: #include <slepc-private/dsimpl.h>
29: #include <slepc-private/vecimplslepc.h>
30: #include <stdlib.h>
34: /*
35: SlepcPrintVersion - Prints SLEPc version info.
37: Collective on MPI_Comm
38: */
39: PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
40: {
42: char version[256];
43:
45: SlepcGetVersion(version,256);
46: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
47: (*PetscHelpPrintf)(comm,"%s\n",version);
48: (*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO);
49: (*PetscHelpPrintf)(comm,"See docs/manual.html for help.\n");
50: (*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR);
51: return(0);
52: }
56: /*
57: SlepcPrintHelpIntro - Prints introductory SLEPc help info.
59: Collective on MPI_Comm
60: */
61: PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
62: {
63: PetscErrorCode ierr;
64:
66: (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
67: (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
68: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
69: return(0);
70: }
72: /* ------------------------Nasty global variables -------------------------------*/
73: /*
74: Indicates whether SLEPc started PETSc, or whether it was
75: already started before SLEPc was initialized.
76: */
77: PetscBool SlepcBeganPetsc = PETSC_FALSE;
78: PetscBool SlepcInitializeCalled = PETSC_FALSE;
79: extern PetscLogEvent SLEPC_UpdateVectors,SLEPC_VecMAXPBY,SLEPC_SlepcDenseMatProd,SLEPC_SlepcDenseOrth,
80: SLEPC_SlepcDenseMatInvProd,SLEPC_SlepcDenseNorm,SLEPC_SlepcDenseCopy,SLEPC_VecsMult;
82: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
83: extern PetscDLLibrary PetscDLLibrariesLoaded;
87: /*
88: SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
89: search path.
90: */
91: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
92: {
94: PetscBool found;
95: char libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
98: PetscStrcpy(libs,SLEPC_LIB_DIR);
99: PetscStrcat(libs,"/libslepc");
100: PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,&found);
101: if (found) {
102: PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,libs);
103: } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries");
104: return(0);
105: }
106: #endif
110: /*
111: SlepcInitialize_Packages - Initialize all SLEPc packages at the initialization.
112: */
113: PetscErrorCode SlepcInitialize_Packages(void)
114: {
118: STInitializePackage(PETSC_NULL);
119: EPSInitializePackage(PETSC_NULL);
120: SVDInitializePackage(PETSC_NULL);
121: QEPInitializePackage(PETSC_NULL);
122: IPInitializePackage(PETSC_NULL);
123: DSInitializePackage(PETSC_NULL);
124: /* New special type of Vec, implemented in SLEPc */
125: VecRegister_Comp(PETSC_NULL);
126: return(0);
127: }
131: /*
132: SlepcInitialize_LogEvents - Initialize log events not pertaining to any object class.
133: */
134: PetscErrorCode SlepcInitialize_LogEvents(void)
135: {
139: PetscLogEventRegister("UpdateVectors",0,&SLEPC_UpdateVectors);
140: PetscLogEventRegister("VecMAXPBY",0,&SLEPC_VecMAXPBY);
141: PetscLogEventRegister("DenseMatProd",EPS_CLASSID,&SLEPC_SlepcDenseMatProd);
142: PetscLogEventRegister("DenseMatNorm",EPS_CLASSID,&SLEPC_SlepcDenseNorm);
143: PetscLogEventRegister("DenseCopy",EPS_CLASSID,&SLEPC_SlepcDenseCopy);
144: PetscLogEventRegister("VecsMult",EPS_CLASSID,&SLEPC_VecsMult);
145: return(0);
146: }
150: /*@C
151: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
152: PetscInitialize() if that has not been called yet, so this routine should
153: always be called near the beginning of your program.
155: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
157: Input Parameters:
158: + argc - count of number of command line arguments
159: . args - the command line arguments
160: . file - [optional] PETSc database file, defaults to ~username/.petscrc
161: (use PETSC_NULL for default)
162: - help - [optional] Help message to print, use PETSC_NULL for no message
164: Fortran Note:
165: Fortran syntax is very similar to that of PetscInitialize()
166:
167: Level: beginner
169: .seealso: SlepcFinalize(), PetscInitialize()
170: @*/
171: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
172: {
174: PetscBool flg;
177: if (SlepcInitializeCalled) {
178: return(0);
179: }
180: PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
181: PetscInitialized(&flg);
182: if (!flg) {
183: PetscInitialize(argc,args,file,help);
184: SlepcBeganPetsc = PETSC_TRUE;
185: }
187: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
188: SlepcInitialize_DynamicLibraries();
189: #else
190: SlepcInitialize_Packages();
191: #endif
192: SlepcInitialize_LogEvents();
194: #if defined(PETSC_HAVE_DRAND48)
195: /* work-around for Cygwin drand48() initialization bug */
196: srand48(0);
197: #endif
199: SlepcInitializeCalled = PETSC_TRUE;
200: PetscInfo(0,"SLEPc successfully started\n");
201: return(0);
202: }
206: /*@
207: SlepcFinalize - Checks for options to be called at the conclusion
208: of the SLEPc program and calls PetscFinalize().
210: Collective on PETSC_COMM_WORLD
212: Level: beginner
214: .seealso: SlepcInitialize(), PetscFinalize()
215: @*/
216: PetscErrorCode SlepcFinalize(void)
217: {
219:
221: PetscInfo(0,"SlepcFinalize() called\n");
222: if (SlepcBeganPetsc) {
223: PetscFinalize();
224: }
225: SlepcInitializeCalled = PETSC_FALSE;
226: return(0);
227: }
231: /*@C
232: SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
233: the command line arguments.
235: Collective
236:
237: Level: advanced
239: .seealso: SlepcInitialize(), SlepcInitializeFortran()
240: @*/
241: PetscErrorCode SlepcInitializeNoArguments(void)
242: {
244: int argc = 0;
245: char **args = 0;
248: SlepcInitialize(&argc,&args,PETSC_NULL,PETSC_NULL);
249: PetscFunctionReturn(ierr);
250: }
254: /*@
255: SlepcInitialized - Determine whether SLEPc is initialized.
256:
257: Level: beginner
259: .seealso: SlepcInitialize(), SlepcInitializeFortran()
260: @*/
261: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
262: {
265: *isInitialized = SlepcInitializeCalled;
266: return(0);
267: }
269: extern PetscBool PetscBeganMPI;
273: /*
274: SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
275: to argc and args (analogue to PetscInitializeNoPointers).
277: Collective
278:
279: Level: advanced
281: .seealso: SlepcInitialize()
282: */
283: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
284: {
286: int myargc = argc;
287: char **myargs = args;
290: SlepcInitialize(&myargc,&myargs,filename,help);
291: PetscPopSignalHandler();
292: PetscBeganMPI = PETSC_FALSE;
293: PetscFunctionReturn(ierr);
294: }
296: #ifdef PETSC_USE_DYNAMIC_LIBRARIES
297: EXTERN_C_BEGIN
300: /*
301: PetscDLLibraryRegister - This function is called when the dynamic library
302: it is in is opened.
304: This one registers all the EPS and ST methods in the libslepc.a
305: library.
307: Input Parameter:
308: path - library path
309: */
310: PetscErrorCode PetscDLLibraryRegister_slepc(char *path)
311: {
314: PetscInitializeNoArguments(); if (ierr) return 1;
317: /*
318: If we got here then PETSc was properly loaded
319: */
320: SlepcInitialize_Packages();
321: return(0);
322: }
323: EXTERN_C_END
324: #endif /* PETSC_USE_DYNAMIC_LIBRARIES */