Actual source code: slepcinit.c

slepc-3.5.2 2014-10-10
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2014, 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: developer
 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:   }
156:   return(0);
157: }
158: #endif

162: /*@C
163:    SlepcInitialize - Initializes the SLEPc library. SlepcInitialize() calls
164:    PetscInitialize() if that has not been called yet, so this routine should
165:    always be called near the beginning of your program.

167:    Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set

169:    Input Parameters:
170: +  argc - count of number of command line arguments
171: .  args - the command line arguments
172: .  file - [optional] PETSc database file, defaults to ~username/.petscrc
173:           (use NULL for default)
174: -  help - [optional] Help message to print, use NULL for no message

176:    Fortran Note:
177:    Fortran syntax is very similar to that of PetscInitialize()

179:    Level: beginner

181: .seealso: SlepcFinalize(), PetscInitialize()
182: @*/
183: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
184: {
186:   PetscBool      flg;

189:   if (SlepcInitializeCalled) return(0);
190:   PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
191:   PetscInitialized(&flg);
192:   if (!flg) {
193:     PetscInitialize(argc,args,file,help);
194:     SlepcBeganPetsc = PETSC_TRUE;
195:   }

197: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
198:   SlepcInitialize_DynamicLibraries();
199: #endif

201: #if defined(PETSC_HAVE_DRAND48)
202:   /* work-around for Cygwin drand48() initialization bug */
203:   srand48(0);
204: #endif

206:   SlepcInitializeCalled = PETSC_TRUE;
207:   PetscInfo(0,"SLEPc successfully started\n");
208:   return(0);
209: }

213: /*@
214:    SlepcFinalize - Checks for options to be called at the conclusion
215:    of the SLEPc program and calls PetscFinalize().

217:    Collective on PETSC_COMM_WORLD

219:    Level: beginner

221: .seealso: SlepcInitialize(), PetscFinalize()
222: @*/
223: PetscErrorCode SlepcFinalize(void)
224: {

228:   PetscInfo(0,"SlepcFinalize() called\n");
229:   if (SlepcBeganPetsc) {
230:     PetscFinalize();
231:   }
232:   SlepcInitializeCalled = PETSC_FALSE;
233:   return(0);
234: }

238: /*@C
239:    SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
240:    the command line arguments.

242:    Collective

244:    Level: advanced

246: .seealso: SlepcInitialize(), SlepcInitializeFortran()
247: @*/
248: PetscErrorCode SlepcInitializeNoArguments(void)
249: {
251:   int            argc = 0;
252:   char           **args = 0;

255:   SlepcInitialize(&argc,&args,NULL,NULL);
256:   PetscFunctionReturn(ierr);
257: }

261: /*@
262:    SlepcInitialized - Determine whether SLEPc is initialized.

264:    Level: beginner

266: .seealso: SlepcInitialize(), SlepcInitializeFortran()
267: @*/
268: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
269: {
272:   *isInitialized = SlepcInitializeCalled;
273:   return(0);
274: }

276: PETSC_EXTERN PetscBool PetscBeganMPI;

280: /*
281:    SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
282:    to argc and args (analogue to PetscInitializeNoPointers).

284:    Collective

286:    Level: advanced

288: .seealso: SlepcInitialize()
289: */
290: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
291: {
293:   int            myargc = argc;
294:   char           **myargs = args;

297:   SlepcInitialize(&myargc,&myargs,filename,help);
298:   PetscPopSignalHandler();
299:   PetscBeganMPI = PETSC_FALSE;
300:   PetscFunctionReturn(ierr);
301: }