Actual source code: slepcinit.c
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2011, 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 <slepcsys.h>
23: #include <private/epsimpl.h> /*I "slepceps.h" I*/
24: #include <private/stimpl.h> /*I "slepcst.h" I*/
25: #include <private/svdimpl.h> /*I "slepcsvd.h" I*/
26: #include <private/qepimpl.h> /*I "slepcqep.h" I*/
27: #include <private/ipimpl.h> /*I "slepcip.h" I*/
28: #include <stdlib.h>
29: #include <slepcvec.h>
33: /*
34: SlepcPrintVersion - Prints SLEPc version info.
36: Collective on MPI_Comm
37: */
38: PetscErrorCode SlepcPrintVersion(MPI_Comm comm)
39: {
41: char version[256];
42:
44: SlepcGetVersion(version,256);
45: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
46: (*PetscHelpPrintf)(comm,"%s\n",version);
47: (*PetscHelpPrintf)(comm,SLEPC_AUTHOR_INFO);
48: (*PetscHelpPrintf)(comm,"See docs/manual.html for help.\n");
49: (*PetscHelpPrintf)(comm,"SLEPc libraries linked from %s\n",SLEPC_LIB_DIR);
50: return(0);
51: }
55: /*
56: SlepcPrintHelpIntro - Prints introductory SLEPc help info.
58: Collective on MPI_Comm
59: */
60: PetscErrorCode SlepcPrintHelpIntro(MPI_Comm comm)
61: {
62: PetscErrorCode ierr;
63:
65: (*PetscHelpPrintf)(comm,"SLEPc help information includes that for the PETSc libraries, which provide\n");
66: (*PetscHelpPrintf)(comm,"low-level system infrastructure and linear algebra tools.\n");
67: (*PetscHelpPrintf)(comm,"--------------------------------------------------------------------------\n");
68: return(0);
69: }
71: /* ------------------------Nasty global variables -------------------------------*/
72: /*
73: Indicates whether SLEPc started PETSc, or whether it was
74: already started before SLEPc was initialized.
75: */
76: PetscBool SlepcBeganPetsc = PETSC_FALSE;
77: PetscBool SlepcInitializeCalled = PETSC_FALSE;
79: SLEPC_SlepcDenseMatInvProd,SLEPC_SlepcDenseNorm,SLEPC_SlepcDenseCopy,SLEPC_VecsMult;
81: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
86: /*
87: SlepcInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
88: search path.
89: */
90: PetscErrorCode SlepcInitialize_DynamicLibraries(void)
91: {
93: PetscBool found;
94: char libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
97: PetscStrcpy(libs,SLEPC_LIB_DIR);
98: PetscStrcat(libs,"/libslepc");
99: PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,&found);
100: if (found) {
101: PetscDLLibraryAppend(PETSC_COMM_WORLD,&DLLibrariesLoaded,libs);
102: } else {
103: SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\n You cannot move the dynamic libraries!");
104: }
105: return(0);
106: }
107: #endif
111: /*
112: SlepcInitialize_Packages - Initialize all SLEPc packages at the initialization.
113: */
114: PetscErrorCode SlepcInitialize_Packages(void)
115: {
119: STInitializePackage(PETSC_NULL);
120: EPSInitializePackage(PETSC_NULL);
121: SVDInitializePackage(PETSC_NULL);
122: QEPInitializePackage(PETSC_NULL);
123: IPInitializePackage(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("DenseOrth",EPS_CLASSID,&SLEPC_SlepcDenseOrth);
143: PetscLogEventRegister("DenseMatNorm",EPS_CLASSID,&SLEPC_SlepcDenseNorm);
144: PetscLogEventRegister("DenseCopy",EPS_CLASSID,&SLEPC_SlepcDenseCopy);
145: PetscLogEventRegister("VecsMult",EPS_CLASSID,&SLEPC_VecsMult);
146: return(0);
147: }
151: /*@C
152: SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
153: PetscInitialize() if that has not been called yet, so this routine should
154: always be called near the beginning of your program.
156: Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
158: Input Parameters:
159: + argc - count of number of command line arguments
160: . args - the command line arguments
161: . file - [optional] PETSc database file, defaults to ~username/.petscrc
162: (use PETSC_NULL for default)
163: - help - [optional] Help message to print, use PETSC_NULL for no message
165: Fortran Note:
166: Fortran syntax is very similar to that of PetscInitialize()
167:
168: Level: beginner
170: .seealso: SlepcFinalize(), PetscInitialize()
171: @*/
172: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
173: {
174: PetscErrorCode ierr,info=0;
175: PetscBool flg;
178: if (SlepcInitializeCalled) {
179: return(0);
180: }
181: info = PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);CHKERRQ(info);
182: PetscInitialized(&flg);
183: if (!flg) {
184: info = PetscInitialize(argc,args,file,help);CHKERRQ(info);
185: SlepcBeganPetsc = PETSC_TRUE;
186: }
188: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
189: SlepcInitialize_DynamicLibraries();
190: #else
191: SlepcInitialize_Packages();
192: #endif
193: SlepcInitialize_LogEvents();
195: #if defined(PETSC_HAVE_DRAND48)
196: /* work-around for Cygwin drand48() initialization bug */
197: srand48(0);
198: #endif
200: SlepcInitializeCalled = PETSC_TRUE;
201: PetscInfo(0,"SLEPc successfully started\n");
202: PetscFunctionReturn(info);
203: }
207: /*@
208: SlepcFinalize - Checks for options to be called at the conclusion
209: of the SLEPc program and calls PetscFinalize().
211: Collective on PETSC_COMM_WORLD
213: Level: beginner
215: .seealso: SlepcInitialize(), PetscFinalize()
216: @*/
217: PetscErrorCode SlepcFinalize(void)
218: {
219: PetscErrorCode info=0;
220:
222: PetscInfo(0,"SLEPc successfully ended!\n");
223: if (SlepcBeganPetsc) {
224: info = PetscFinalize();CHKERRQ(info);
225: }
226: SlepcInitializeCalled = PETSC_FALSE;
227: PetscFunctionReturn(info);
228: }
232: /*@
233: SlepcInitialized - Determine whether SLEPc is initialized.
234:
235: Level: beginner
237: .seealso: SlepcInitialize(), SlepcInitializeFortran()
238: @*/
239: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
240: {
243: *isInitialized = SlepcInitializeCalled;
244: return(0);
245: }
247: #if defined(PETSC_HAVE_MATLAB_ENGINE)
252: /*
253: SlepcInitializeMatlab - Calls SlepcInitialize() from MATLAB (analogue to
254: PetscInitializeMatlab).
256: Collective
257:
258: Level: advanced
260: .seealso: SlepcInitialize()
261: */
262: PetscErrorCode SlepcInitializeMatlab(int argc,char **args,const char *filename,const char *help)
263: {
265: int myargc = argc;
266: char **myargs = args;
269: SlepcInitialize(&myargc,&myargs,filename,help);
270: PetscPopSignalHandler();
271: PetscBeganMPI = PETSC_FALSE;
272: PetscFunctionReturn(ierr);
273: }
277: /*
278: SlepcInitializedMatlab - Has SLEPc been initialized already?
280: Not Collective
281:
282: Level: advanced
284: Notes: this is called only by the SLEPc MATLAB interface.
286: .seealso: SlepcInitialize()
287: */
288: int SlepcInitializedMatlab(void)
289: {
290: PetscBool flg;
292: SlepcInitialized(&flg);
293: if (flg) return 1;
294: else return 0;
295: }
296: #endif
298: #ifdef PETSC_USE_DYNAMIC_LIBRARIES
302: /*
303: PetscDLLibraryRegister - This function is called when the dynamic library
304: it is in is opened.
306: This one registers all the EPS and ST methods in the libslepc.a
307: library.
309: Input Parameter:
310: path - library path
311: */
312: PetscErrorCode PetscDLLibraryRegister_slepc(char *path)
313: {
316: PetscInitializeNoArguments(); if (ierr) return 1;
319: /*
320: If we got here then PETSc was properly loaded
321: */
322: SlepcInitialize_Packages();
323: return(0);
324: }
326: #endif /* PETSC_USE_DYNAMIC_LIBRARIES */