Actual source code: slepcinit.c

slepc-3.7.4 2017-05-17
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2016, 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,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:     "   doi = \"http://dx.doi.org/10.1145/1089014.1089019\"\n"
189:     "}\n",NULL);
190:   PetscCitationsRegister("@TechReport{slepc-manual,\n"
191:     "   author = \"J. E. Roman and C. Campos and E. Romero and A. Tomas\",\n"
192:     "   title = \"{SLEPc} Users Manual\",\n"
193:     "   number = \"DSIC-II/24/02 - Revision 3.7\",\n"
194:     "   institution = \"D. Sistemes Inform\\`atics i Computaci\\'o, Universitat Polit\\`ecnica de Val\\`encia\",\n"
195:     "   year = \"2016\"\n"
196:     "}\n",NULL);
197:   return(0);
198: }

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

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

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

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

219:    Level: beginner

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

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

237:   SlepcCitationsInitialize();

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

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

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

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

259:    Collective on PETSC_COMM_WORLD

261:    Level: beginner

263: .seealso: SlepcInitialize(), PetscFinalize()
264: @*/
265: PetscErrorCode SlepcFinalize(void)
266: {
267:   PetscErrorCode 0;

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

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

284:    Collective

286:    Level: advanced

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

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

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

306:    Level: beginner

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

318: PETSC_EXTERN PetscBool PetscBeganMPI;

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

326:    Collective

328:    Level: advanced

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

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