Actual source code: slepcinit.c

slepc-3.6.1 2015-09-03
Report Typos and Errors
  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: PetscErrorCode SlepcCitationsInitialize()
176: {

180:   PetscCitationsRegister("@Article{slepc-toms,\n"
181:     "   author = \"Vicente Hernandez and Jose E. Roman and Vicente Vidal\",\n"
182:     "   title = \"{SLEPc}: A Scalable and Flexible Toolkit for the Solution of Eigenvalue Problems\",\n"
183:     "   journal = \"{ACM} Trans. Math. Software\",\n"
184:     "   volume = \"31\",\n"
185:     "   number = \"3\",\n"
186:     "   pages = \"351--362\",\n"
187:     "   year = \"2005\"\n"
188:     "}\n",NULL);
189:   PetscCitationsRegister("@TechReport{slepc-manual,\n"
190:     "   author = \"J. E. Roman and C. Campos and E. Romero and A. Tomas\",\n"
191:     "   title = \"{SLEPc} Users Manual\",\n"
192:     "   number = \"DSIC-II/24/02 - Revision 3.6\",\n"
193:     "   institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
194:     "   year = \"2015\"\n"
195:     "}\n",NULL);
196:   return(0);
197: }

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

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

208:    Input Parameters:
209: +  argc - count of number of command line arguments
210: .  args - the command line arguments
211: .  file - [optional] PETSc database file, defaults to ~username/.petscrc
212:           (use NULL for default)
213: -  help - [optional] Help message to print, use NULL for no message

215:    Fortran Note:
216:    Fortran syntax is very similar to that of PetscInitialize()

218:    Level: beginner

220: .seealso: SlepcFinalize(), PetscInitialize()
221: @*/
222: PetscErrorCode SlepcInitialize(int *argc,char ***args,const char file[],const char help[])
223: {
225:   PetscBool      flg;

228:   if (SlepcInitializeCalled) return(0);
229:   PetscSetHelpVersionFunctions(SlepcPrintHelpIntro,SlepcPrintVersion);
230:   PetscInitialized(&flg);
231:   if (!flg) {
232:     PetscInitialize(argc,args,file,help);
233:     SlepcBeganPetsc = PETSC_TRUE;
234:   }

236:   SlepcCitationsInitialize();

238: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
239:   SlepcInitialize_DynamicLibraries();
240: #endif

242: #if defined(PETSC_HAVE_DRAND48)
243:   /* work-around for Cygwin drand48() initialization bug */
244:   srand48(0);
245: #endif

247:   SlepcInitializeCalled = PETSC_TRUE;
248:   PetscInfo(0,"SLEPc successfully started\n");
249:   return(0);
250: }

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

258:    Collective on PETSC_COMM_WORLD

260:    Level: beginner

262: .seealso: SlepcInitialize(), PetscFinalize()
263: @*/
264: PetscErrorCode SlepcFinalize(void)
265: {

269:   PetscInfo(0,"SlepcFinalize() called\n");
270:   if (SlepcBeganPetsc) {
271:     PetscFinalize();
272:   }
273:   SlepcInitializeCalled = PETSC_FALSE;
274:   return(0);
275: }

279: /*@C
280:    SlepcInitializeNoArguments - Calls SlepcInitialize() from C/C++ without
281:    the command line arguments.

283:    Collective

285:    Level: advanced

287: .seealso: SlepcInitialize(), SlepcInitializeFortran()
288: @*/
289: PetscErrorCode SlepcInitializeNoArguments(void)
290: {
292:   int            argc = 0;
293:   char           **args = 0;

296:   SlepcInitialize(&argc,&args,NULL,NULL);
297:   PetscFunctionReturn(ierr);
298: }

302: /*@
303:    SlepcInitialized - Determine whether SLEPc is initialized.

305:    Level: beginner

307: .seealso: SlepcInitialize(), SlepcInitializeFortran()
308: @*/
309: PetscErrorCode SlepcInitialized(PetscBool *isInitialized)
310: {
313:   *isInitialized = SlepcInitializeCalled;
314:   return(0);
315: }

317: PETSC_EXTERN PetscBool PetscBeganMPI;

321: /*
322:    SlepcInitializeNoPointers - Calls SlepcInitialize() from C/C++ without the pointers
323:    to argc and args (analogue to PetscInitializeNoPointers).

325:    Collective

327:    Level: advanced

329: .seealso: SlepcInitialize()
330: */
331: PetscErrorCode SlepcInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
332: {
334:   int            myargc = argc;
335:   char           **myargs = args;

338:   SlepcInitialize(&myargc,&myargs,filename,help);
339:   PetscPopSignalHandler();
340:   PetscBeganMPI = PETSC_FALSE;
341:   PetscFunctionReturn(ierr);
342: }