Actual source code: pinit.c

petsc-master 2018-05-23
Report Typos and Errors

  2: /*
  3:    This file defines the initialization of PETSc, including PetscInitialize()
  4: */
  5:  #include <petsc/private/petscimpl.h>
  6:  #include <petscvalgrind.h>
  7:  #include <petscviewer.h>

  9: #if defined(PETSC_USE_LOG)
 10: extern PetscErrorCode PetscLogInitialize(void);
 11: #endif

 13: #if defined(PETSC_SERIALIZE_FUNCTIONS)
 14: PetscFPT PetscFPTData = 0;
 15: #endif

 17: #if defined(PETSC_HAVE_SAWS)
 18:  #include <petscviewersaws.h>
 19: #endif
 20: /* -----------------------------------------------------------------------------------------*/

 22: extern FILE *petsc_history;

 24: extern PetscErrorCode PetscInitialize_DynamicLibraries(void);
 25: extern PetscErrorCode PetscFinalize_DynamicLibraries(void);
 26: extern PetscErrorCode PetscFunctionListPrintAll(void);
 27: extern PetscErrorCode PetscSequentialPhaseBegin_Private(MPI_Comm,int);
 28: extern PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm,int);
 29: extern PetscErrorCode PetscCloseHistoryFile(FILE**);

 31: /* user may set this BEFORE calling PetscInitialize() */
 32: MPI_Comm PETSC_COMM_WORLD = MPI_COMM_NULL;

 34: PetscMPIInt Petsc_Counter_keyval   = MPI_KEYVAL_INVALID;
 35: PetscMPIInt Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID;
 36: PetscMPIInt Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID;
 37: PetscMPIInt Petsc_Shared_keyval    = MPI_KEYVAL_INVALID;

 39: /*
 40:      Declare and set all the string names of the PETSc enums
 41: */
 42: const char *const PetscBools[]     = {"FALSE","TRUE","PetscBool","PETSC_",0};
 43: const char *const PetscCopyModes[] = {"COPY_VALUES","OWN_POINTER","USE_POINTER","PetscCopyMode","PETSC_",0};
 44: const char *const PetscDataTypes[] = {"INT","DOUBLE","COMPLEX","LONG","SHORT","FLOAT",
 45:                                       "CHAR","LOGICAL","ENUM","BOOL","LONGDOUBLE","OBJECT","FUNCTION","PetscDataType","PETSC_",0};

 47: PetscBool PetscPreLoadingUsed = PETSC_FALSE;
 48: PetscBool PetscPreLoadingOn   = PETSC_FALSE;

 50: PetscInt PetscHotRegionDepth;

 52: #if defined(PETSC_HAVE_THREADSAFETY)
 53: PetscSpinlock PetscViewerASCIISpinLockOpen;
 54: PetscSpinlock PetscViewerASCIISpinLockStdout;
 55: PetscSpinlock PetscViewerASCIISpinLockStderr;
 56: PetscSpinlock PetscCommSpinLock;
 57: #endif

 59: /*
 60:        Checks the options database for initializations related to the
 61:     PETSc components
 62: */
 63: PetscErrorCode  PetscOptionsCheckInitial_Components(void)
 64: {
 65:   PetscBool      flg1;

 69:   PetscOptionsHasName(NULL,NULL,"-help",&flg1);
 70:   if (flg1) {
 71: #if defined(PETSC_USE_LOG)
 72:     MPI_Comm comm = PETSC_COMM_WORLD;
 73:     (*PetscHelpPrintf)(comm,"------Additional PETSc component options--------\n");
 74:     (*PetscHelpPrintf)(comm," -log_exclude: <vec,mat,pc,ksp,snes,tao,ts>\n");
 75:     (*PetscHelpPrintf)(comm," -info_exclude: <null,vec,mat,pc,ksp,snes,tao,ts>\n");
 76:     (*PetscHelpPrintf)(comm,"-----------------------------------------------\n");
 77: #endif
 78:   }
 79:   return(0);
 80: }

 82: /*
 83:       PetscInitializeNoPointers - Calls PetscInitialize() from C/C++ without the pointers to argc and args

 85:    Collective

 87:    Level: advanced

 89:     Notes:
 90:     this is called only by the PETSc MATLAB and Julia interface. Even though it might start MPI it sets the flag to
 91:      indicate that it did NOT start MPI so that the PetscFinalize() does not end MPI, thus allowing PetscInitialize() to
 92:      be called multiple times from MATLAB and Julia without the problem of trying to initialize MPI more than once.

 94:      Turns off PETSc signal handling because that can interact with MATLAB's signal handling causing random crashes.

 96: .seealso: PetscInitialize(), PetscInitializeFortran(), PetscInitializeNoArguments()
 97: */
 98: PetscErrorCode  PetscInitializeNoPointers(int argc,char **args,const char *filename,const char *help)
 99: {
101:   int            myargc   = argc;
102:   char           **myargs = args;

105:   PetscInitialize(&myargc,&myargs,filename,help);
106:   PetscPopSignalHandler();
107:   PetscBeganMPI = PETSC_FALSE;
108:   PetscFunctionReturn(ierr);
109: }

111: /*
112:       Used by MATLAB and Julia interface to get communicator
113: */
114: PetscErrorCode  PetscGetPETSC_COMM_SELF(MPI_Comm *comm)
115: {
117:   *comm = PETSC_COMM_SELF;
118:   return(0);
119: }

121: /*@C
122:       PetscInitializeNoArguments - Calls PetscInitialize() from C/C++ without
123:         the command line arguments.

125:    Collective

127:    Level: advanced

129: .seealso: PetscInitialize(), PetscInitializeFortran()
130: @*/
131: PetscErrorCode  PetscInitializeNoArguments(void)
132: {
134:   int            argc   = 0;
135:   char           **args = 0;

138:   PetscInitialize(&argc,&args,NULL,NULL);
139:   PetscFunctionReturn(ierr);
140: }

142: /*@
143:       PetscInitialized - Determine whether PETSc is initialized.

145:    Level: beginner

147: .seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran()
148: @*/
149: PetscErrorCode PetscInitialized(PetscBool  *isInitialized)
150: {
151:   *isInitialized = PetscInitializeCalled;
152:   return 0;
153: }

155: /*@
156:       PetscFinalized - Determine whether PetscFinalize() has been called yet

158:    Level: developer

160: .seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran()
161: @*/
162: PetscErrorCode  PetscFinalized(PetscBool  *isFinalized)
163: {
164:   *isFinalized = PetscFinalizeCalled;
165:   return 0;
166: }

168: extern PetscErrorCode PetscOptionsCheckInitial_Private(void);

170: /*
171:        This function is the MPI reduction operation used to compute the sum of the
172:    first half of the datatype and the max of the second half.
173: */
174: MPI_Op MPIU_MAXSUM_OP = 0;

176: PETSC_INTERN void MPIAPI MPIU_MaxSum_Local(void *in,void *out,int *cnt,MPI_Datatype *datatype)
177: {
178:   PetscInt *xin = (PetscInt*)in,*xout = (PetscInt*)out,i,count = *cnt;

181:   if (*datatype != MPIU_2INT) {
182:     (*PetscErrorPrintf)("Can only handle MPIU_2INT data types");
183:     MPI_Abort(MPI_COMM_WORLD,1);
184:   }

186:   for (i=0; i<count; i++) {
187:     xout[2*i]    = PetscMax(xout[2*i],xin[2*i]);
188:     xout[2*i+1] += xin[2*i+1];
189:   }
190:   PetscFunctionReturnVoid();
191: }

193: /*
194:     Returns the max of the first entry owned by this processor and the
195: sum of the second entry.

197:     The reason sizes[2*i] contains lengths sizes[2*i+1] contains flag of 1 if length is nonzero
198: is so that the MPIU_MAXSUM_OP() can set TWO values, if we passed in only sizes[i] with lengths
199: there would be no place to store the both needed results.
200: */
201: PetscErrorCode  PetscMaxSum(MPI_Comm comm,const PetscInt sizes[],PetscInt *max,PetscInt *sum)
202: {

206: #if defined(PETSC_HAVE_MPI_REDUCE_SCATTER_BLOCK)
207:   {
208:     struct {PetscInt max,sum;} work;
209:     MPI_Reduce_scatter_block((void*)sizes,&work,1,MPIU_2INT,MPIU_MAXSUM_OP,comm);
210:     *max = work.max;
211:     *sum = work.sum;
212:   }
213: #else
214:   {
215:     PetscMPIInt    size,rank;
216:     struct {PetscInt max,sum;} *work;
217:     MPI_Comm_size(comm,&size);
218:     MPI_Comm_rank(comm,&rank);
219:     PetscMalloc1(size,&work);
220:     MPIU_Allreduce((void*)sizes,work,size,MPIU_2INT,MPIU_MAXSUM_OP,comm);
221:     *max = work[rank].max;
222:     *sum = work[rank].sum;
223:     PetscFree(work);
224:   }
225: #endif
226:   return(0);
227: }

229: /* ----------------------------------------------------------------------------*/

231: #if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
232: MPI_Op MPIU_SUM = 0;

234: PETSC_EXTERN void PetscSum_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
235: {
236:   PetscInt i,count = *cnt;

239:   if (*datatype == MPIU_REAL) {
240:     PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
241:     for (i=0; i<count; i++) xout[i] += xin[i];
242:   }
243: #if defined(PETSC_HAVE_COMPLEX)
244:   else if (*datatype == MPIU_COMPLEX) {
245:     PetscComplex *xin = (PetscComplex*)in,*xout = (PetscComplex*)out;
246:     for (i=0; i<count; i++) xout[i] += xin[i];
247:   }
248: #endif
249:   else {
250:     (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types");
251:     MPI_Abort(MPI_COMM_WORLD,1);
252:   }
253:   PetscFunctionReturnVoid();
254: }
255: #endif

257: #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
258: MPI_Op MPIU_MAX = 0;
259: MPI_Op MPIU_MIN = 0;

261: PETSC_EXTERN void PetscMax_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
262: {
263:   PetscInt i,count = *cnt;

266:   if (*datatype == MPIU_REAL) {
267:     PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
268:     for (i=0; i<count; i++) xout[i] = PetscMax(xout[i],xin[i]);
269:   }
270: #if defined(PETSC_HAVE_COMPLEX)
271:   else if (*datatype == MPIU_COMPLEX) {
272:     PetscComplex *xin = (PetscComplex*)in,*xout = (PetscComplex*)out;
273:     for (i=0; i<count; i++) {
274:       xout[i] = PetscRealPartComplex(xout[i])<PetscRealPartComplex(xin[i]) ? xin[i] : xout[i];
275:     }
276:   }
277: #endif
278:   else {
279:     (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types");
280:     MPI_Abort(MPI_COMM_WORLD,1);
281:   }
282:   PetscFunctionReturnVoid();
283: }

285: PETSC_EXTERN void PetscMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
286: {
287:   PetscInt    i,count = *cnt;

290:   if (*datatype == MPIU_REAL) {
291:     PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
292:     for (i=0; i<count; i++) xout[i] = PetscMin(xout[i],xin[i]);
293:   }
294: #if defined(PETSC_HAVE_COMPLEX)
295:   else if (*datatype == MPIU_COMPLEX) {
296:     PetscComplex *xin = (PetscComplex*)in,*xout = (PetscComplex*)out;
297:     for (i=0; i<count; i++) {
298:       xout[i] = PetscRealPartComplex(xout[i])>PetscRealPartComplex(xin[i]) ? xin[i] : xout[i];
299:     }
300:   }
301: #endif
302:   else {
303:     (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_SCALAR data (i.e. double or complex) types");
304:     MPI_Abort(MPI_COMM_WORLD,1);
305:   }
306:   PetscFunctionReturnVoid();
307: }
308: #endif

310: /*
311:    Private routine to delete internal tag/name counter storage when a communicator is freed.

313:    This is called by MPI, not by users. This is called by MPI_Comm_free() when the communicator that has this  data as an attribute is freed.

315:    Note: this is declared extern "C" because it is passed to MPI_Comm_create_keyval()

317: */
318: PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelCounter(MPI_Comm comm,PetscMPIInt keyval,void *count_val,void *extra_state)
319: {

323:   PetscInfo1(0,"Deleting counter data in an MPI_Comm %ld\n",(long)comm);CHKERRMPI(ierr);
324:   PetscFree(count_val);CHKERRMPI(ierr);
325:   PetscFunctionReturn(MPI_SUCCESS);
326: }

328: /*
329:   This is invoked on the outer comm as a result of either PetscCommDestroy() (via MPI_Comm_delete_attr) or when the user
330:   calls MPI_Comm_free().

332:   This is the only entry point for breaking the links between inner and outer comms.

334:   This is called by MPI, not by users. This is called when MPI_Comm_free() is called on the communicator.

336:   Note: this is declared extern "C" because it is passed to MPI_Comm_create_keyval()

338: */
339: PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Outer(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state)
340: {
341:   PetscErrorCode                    ierr;
342:   PetscMPIInt                       flg;
343:   union {MPI_Comm comm; void *ptr;} icomm,ocomm;

346:   if (keyval != Petsc_InnerComm_keyval) SETERRMPI(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Unexpected keyval");
347:   icomm.ptr = attr_val;

349:   MPI_Comm_get_attr(icomm.comm,Petsc_OuterComm_keyval,&ocomm,&flg);CHKERRMPI(ierr);
350:   if (!flg) SETERRMPI(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm does not have expected reference to outer comm");
351:   if (ocomm.comm != comm) SETERRMPI(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm has reference to non-matching outer comm");
352:   MPI_Comm_delete_attr(icomm.comm,Petsc_OuterComm_keyval);CHKERRMPI(ierr);
353:   PetscInfo1(0,"User MPI_Comm %ld is being freed after removing reference from inner PETSc comm to this outer comm\n",(long)comm);CHKERRMPI(ierr);
354:   PetscFunctionReturn(MPI_SUCCESS);
355: }

357: /*
358:  * This is invoked on the inner comm when Petsc_DelComm_Outer calls MPI_Comm_delete_attr.  It should not be reached any other way.
359:  */
360: PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Inner(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state)
361: {

365:   PetscInfo1(0,"Removing reference to PETSc communicator embedded in a user MPI_Comm %ld\n",(long)comm);CHKERRMPI(ierr);
366:   PetscFunctionReturn(MPI_SUCCESS);
367: }

369: PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelShared(MPI_Comm,PetscMPIInt,void *,void *);

371: #if defined(PETSC_USE_PETSC_MPI_EXTERNAL32)
372: #if !defined(PETSC_WORDS_BIGENDIAN)
373: PETSC_EXTERN PetscMPIInt PetscDataRep_extent_fn(MPI_Datatype,MPI_Aint*,void*);
374: PETSC_EXTERN PetscMPIInt PetscDataRep_read_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*);
375: PETSC_EXTERN PetscMPIInt PetscDataRep_write_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*);
376: #endif
377: #endif

379: PetscMPIInt PETSC_MPI_ERROR_CLASS,PETSC_MPI_ERROR_CODE;

381: int  PetscGlobalArgc   = 0;
382: char **PetscGlobalArgs = 0;
383: PetscSegBuffer PetscCitationsList;

385: PetscErrorCode PetscCitationsInitialize(void)
386: {

390:   PetscSegBufferCreate(1,10000,&PetscCitationsList);
391:   PetscCitationsRegister("@TechReport{petsc-user-ref,\n  Author = {Satish Balay and Shrirang Abhyankar and Mark F. Adams and Jed Brown and Peter Brune\n            and Kris Buschelman and Lisandro Dalcin and Victor Eijkhout and William D. Gropp\n            and Dinesh Kaushik and Matthew G. Knepley and Dave A. May and Lois Curfman McInnes\n            and Richard Tran Mills and Todd Munson and Karl Rupp and Patrick Sanan\n            and Barry F. Smith and Stefano Zampini and Hong Zhang and Hong Zhang},\n  Title = {{PETS}c Users Manual},\n  Number = {ANL-95/11 - Revision 3.9},\n  Institution = {Argonne National Laboratory},\n  Year = {2018}\n}\n",NULL);
392:   PetscCitationsRegister("@InProceedings{petsc-efficient,\n  Author = {Satish Balay and William D. Gropp and Lois Curfman McInnes and Barry F. Smith},\n  Title = {Efficient Management of Parallelism in Object Oriented Numerical Software Libraries},\n  Booktitle = {Modern Software Tools in Scientific Computing},\n  Editor = {E. Arge and A. M. Bruaset and H. P. Langtangen},\n  Pages = {163--202},\n  Publisher = {Birkh{\\\"{a}}user Press},\n  Year = {1997}\n}\n",NULL);
393:   return(0);
394: }

396: /*@C
397:    PetscGetArgs - Allows you to access the raw command line arguments anywhere
398:      after PetscInitialize() is called but before PetscFinalize().

400:    Not Collective

402:    Output Parameters:
403: +  argc - count of number of command line arguments
404: -  args - the command line arguments

406:    Level: intermediate

408:    Notes:
409:       This is usually used to pass the command line arguments into other libraries
410:    that are called internally deep in PETSc or the application.

412:       The first argument contains the program name as is normal for C arguments.

414:    Concepts: command line arguments

416: .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArguments()

418: @*/
419: PetscErrorCode  PetscGetArgs(int *argc,char ***args)
420: {
422:   if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
423:   *argc = PetscGlobalArgc;
424:   *args = PetscGlobalArgs;
425:   return(0);
426: }

428: /*@C
429:    PetscGetArguments - Allows you to access the  command line arguments anywhere
430:      after PetscInitialize() is called but before PetscFinalize().

432:    Not Collective

434:    Output Parameters:
435: .  args - the command line arguments

437:    Level: intermediate

439:    Notes:
440:       This does NOT start with the program name and IS null terminated (final arg is void)

442:    Concepts: command line arguments

444: .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscFreeArguments()

446: @*/
447: PetscErrorCode  PetscGetArguments(char ***args)
448: {
449:   PetscInt       i,argc = PetscGlobalArgc;

453:   if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
454:   if (!argc) {*args = 0; return(0);}
455:   PetscMalloc1(argc,args);
456:   for (i=0; i<argc-1; i++) {
457:     PetscStrallocpy(PetscGlobalArgs[i+1],&(*args)[i]);
458:   }
459:   (*args)[argc-1] = 0;
460:   return(0);
461: }

463: /*@C
464:    PetscFreeArguments - Frees the memory obtained with PetscGetArguments()

466:    Not Collective

468:    Output Parameters:
469: .  args - the command line arguments

471:    Level: intermediate

473:    Concepts: command line arguments

475: .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscGetArguments()

477: @*/
478: PetscErrorCode  PetscFreeArguments(char **args)
479: {
480:   PetscInt       i = 0;

484:   if (!args) return(0);
485:   while (args[i]) {
486:     PetscFree(args[i]);
487:     i++;
488:   }
489:   PetscFree(args);
490:   return(0);
491: }

493: #if defined(PETSC_HAVE_SAWS)
494: #include <petscconfiginfo.h>

496: PetscErrorCode  PetscInitializeSAWs(const char help[])
497: {
498:   if (!PetscGlobalRank) {
499:     char           cert[PETSC_MAX_PATH_LEN],root[PETSC_MAX_PATH_LEN],*intro,programname[64],*appline,*options,version[64];
500:     int            port;
501:     PetscBool      flg,rootlocal = PETSC_FALSE,flg2,selectport = PETSC_FALSE;
502:     size_t         applinelen,introlen;
504:     char           sawsurl[256];

506:     PetscOptionsHasName(NULL,NULL,"-saws_log",&flg);
507:     if (flg) {
508:       char  sawslog[PETSC_MAX_PATH_LEN];

510:       PetscOptionsGetString(NULL,NULL,"-saws_log",sawslog,PETSC_MAX_PATH_LEN,NULL);
511:       if (sawslog[0]) {
512:         PetscStackCallSAWs(SAWs_Set_Use_Logfile,(sawslog));
513:       } else {
514:         PetscStackCallSAWs(SAWs_Set_Use_Logfile,(NULL));
515:       }
516:     }
517:     PetscOptionsGetString(NULL,NULL,"-saws_https",cert,PETSC_MAX_PATH_LEN,&flg);
518:     if (flg) {
519:       PetscStackCallSAWs(SAWs_Set_Use_HTTPS,(cert));
520:     }
521:     PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select",&selectport,NULL);
522:     if (selectport) {
523:         PetscStackCallSAWs(SAWs_Get_Available_Port,(&port));
524:         PetscStackCallSAWs(SAWs_Set_Port,(port));
525:     } else {
526:       PetscOptionsGetInt(NULL,NULL,"-saws_port",&port,&flg);
527:       if (flg) {
528:         PetscStackCallSAWs(SAWs_Set_Port,(port));
529:       }
530:     }
531:     PetscOptionsGetString(NULL,NULL,"-saws_root",root,PETSC_MAX_PATH_LEN,&flg);
532:     if (flg) {
533:       PetscStackCallSAWs(SAWs_Set_Document_Root,(root));
534:       PetscStrcmp(root,".",&rootlocal);
535:     } else {
536:       PetscOptionsHasName(NULL,NULL,"-saws_options",&flg);
537:       if (flg) {
538:         PetscStrreplace(PETSC_COMM_WORLD,"${PETSC_DIR}/share/petsc/saws",root,PETSC_MAX_PATH_LEN);
539:         PetscStackCallSAWs(SAWs_Set_Document_Root,(root));
540:       }
541:     }
542:     PetscOptionsHasName(NULL,NULL,"-saws_local",&flg2);
543:     if (flg2) {
544:       char jsdir[PETSC_MAX_PATH_LEN];
545:       if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"-saws_local option requires -saws_root option");
546:       PetscSNPrintf(jsdir,PETSC_MAX_PATH_LEN,"%s/js",root);
547:       PetscTestDirectory(jsdir,'r',&flg);
548:       if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_READ,"-saws_local option requires js directory in root directory");
549:       PetscStackCallSAWs(SAWs_Push_Local_Header,());
550:     }
551:     PetscGetProgramName(programname,64);
552:     PetscStrlen(help,&applinelen);
553:     introlen   = 4096 + applinelen;
554:     applinelen += 1024;
555:     PetscMalloc(applinelen,&appline);
556:     PetscMalloc(introlen,&intro);

558:     if (rootlocal) {
559:       PetscSNPrintf(appline,applinelen,"%s.c.html",programname);
560:       PetscTestFile(appline,'r',&rootlocal);
561:     }
562:     PetscOptionsGetAll(NULL,&options);
563:     if (rootlocal && help) {
564:       PetscSNPrintf(appline,applinelen,"<center> Running <a href=\"%s.c.html\">%s</a> %s</center><br><center><pre>%s</pre></center><br>\n",programname,programname,options,help);
565:     } else if (help) {
566:       PetscSNPrintf(appline,applinelen,"<center>Running %s %s</center><br><center><pre>%s</pre></center><br>",programname,options,help);
567:     } else {
568:       PetscSNPrintf(appline,applinelen,"<center> Running %s %s</center><br>\n",programname,options);
569:     }
570:     PetscFree(options);
571:     PetscGetVersion(version,sizeof(version));
572:     PetscSNPrintf(intro,introlen,"<body>\n"
573:                                     "<center><h2> <a href=\"http://www.mcs.anl.gov/petsc\">PETSc</a> Application Web server powered by <a href=\"https://bitbucket.org/saws/saws\">SAWs</a> </h2></center>\n"
574:                                     "<center>This is the default PETSc application dashboard, from it you can access any published PETSc objects or logging data</center><br><center>%s configured with %s</center><br>\n"
575:                                     "%s",version,petscconfigureoptions,appline);
576:     PetscStackCallSAWs(SAWs_Push_Body,("index.html",0,intro));
577:     PetscFree(intro);
578:     PetscFree(appline);
579:     if (selectport) {
580:       PetscBool silent;

582:       SAWs_Initialize();
583:       /* another process may have grabbed the port so keep trying */
584:       while (ierr) {
585:         PetscStackCallSAWs(SAWs_Get_Available_Port,(&port));
586:         PetscStackCallSAWs(SAWs_Set_Port,(port));
587:         SAWs_Initialize();
588:       }

590:       PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select_silent",&silent,NULL);
591:       if (!silent) {
592:         PetscStackCallSAWs(SAWs_Get_FullURL,(sizeof(sawsurl),sawsurl));
593:         PetscPrintf(PETSC_COMM_WORLD,"Point your browser to %s for SAWs\n",sawsurl);
594:       }
595:     } else {
596:       PetscStackCallSAWs(SAWs_Initialize,());
597:     }
598:     PetscCitationsRegister("@TechReport{ saws,\n"
599:                                   "  Author = {Matt Otten and Jed Brown and Barry Smith},\n"
600:                                   "  Title  = {Scientific Application Web Server (SAWs) Users Manual},\n"
601:                                   "  Institution = {Argonne National Laboratory},\n"
602:                                   "  Year   = 2013\n}\n",NULL);
603:   }
604:   return(0);
605: }
606: #endif

608: /*@C
609:    PetscInitialize - Initializes the PETSc database and MPI.
610:    PetscInitialize() calls MPI_Init() if that has yet to be called,
611:    so this routine should always be called near the beginning of
612:    your program -- usually the very first line!

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

616:    Input Parameters:
617: +  argc - count of number of command line arguments
618: .  args - the command line arguments
619: .  file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use NULL to not check for
620:           code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files
621: -  help - [optional] Help message to print, use NULL for no message

623:    If you wish PETSc code to run ONLY on a subcommunicator of MPI_COMM_WORLD, create that
624:    communicator first and assign it to PETSC_COMM_WORLD BEFORE calling PetscInitialize(). Thus if you are running a
625:    four process job and two processes will run PETSc and have PetscInitialize() and PetscFinalize() and two process will not,
626:    then do this. If ALL processes in the job are using PetscInitialize() and PetscFinalize() then you don't need to do this, even
627:    if different subcommunicators of the job are doing different things with PETSc.

629:    Options Database Keys:
630: +  -help [intro] - prints help method for each option; if intro is given the program stops after printing the introductory help message
631: .  -start_in_debugger [noxterm,dbx,xdb,gdb,...] - Starts program in debugger
632: .  -on_error_attach_debugger [noxterm,dbx,xdb,gdb,...] - Starts debugger when error detected
633: .  -on_error_emacs <machinename> causes emacsclient to jump to error file
634: .  -on_error_abort calls abort() when error detected (no traceback)
635: .  -on_error_mpiabort calls MPI_abort() when error detected
636: .  -error_output_stderr prints error messages to stderr instead of the default stdout
637: .  -error_output_none does not print the error messages (but handles errors in the same way as if this was not called)
638: .  -debugger_nodes [node1,node2,...] - Indicates nodes to start in debugger
639: .  -debugger_pause [sleeptime] (in seconds) - Pauses debugger
640: .  -stop_for_debugger - Print message on how to attach debugger manually to
641:                         process and wait (-debugger_pause) seconds for attachment
642: .  -malloc - Indicates use of PETSc error-checking malloc (on by default for debug version of libraries)
643: .  -malloc no - Indicates not to use error-checking malloc
644: .  -malloc_debug - check for memory corruption at EVERY malloc or free
645: .  -malloc_dump - prints a list of all unfreed memory at the end of the run
646: .  -malloc_test - like -malloc_dump -malloc_debug, but only active for debugging builds
647: .  -fp_trap - Stops on floating point exceptions (Note that on the
648:               IBM RS6000 this slows code by at least a factor of 10.)
649: .  -no_signal_handler - Indicates not to trap error signals
650: .  -shared_tmp - indicates /tmp directory is shared by all processors
651: .  -not_shared_tmp - each processor has own /tmp
652: .  -tmp - alternative name of /tmp directory
653: .  -get_total_flops - returns total flops done by all processors
654: -  -memory_view - Print memory usage at end of run

656:    Options Database Keys for Profiling:
657:    See Users-Manual: Chapter 13 Profiling for details.
658: +  -info <optional filename> - Prints verbose information to the screen
659: .  -info_exclude <null,vec,mat,pc,ksp,snes,ts> - Excludes some of the verbose messages
660: .  -log_sync - Log the synchronization in scatters, inner products and norms
661: .  -log_trace [filename] - Print traces of all PETSc calls to the screen (useful to determine where a program
662:         hangs without running in the debugger).  See PetscLogTraceBegin().
663: .  -log_view [:filename:format] - Prints summary of flop and timing information to screen or file, see PetscLogView().
664: .  -log_summary [filename] - (Deprecated, use -log_view) Prints summary of flop and timing information to screen. If the filename is specified the
665:         summary is written to the file.  See PetscLogView().
666: .  -log_exclude: <vec,mat,pc.ksp,snes> - excludes subset of object classes from logging
667: .  -log_all [filename] - Logs extensive profiling information  See PetscLogDump().
668: .  -log [filename] - Logs basic profiline information  See PetscLogDump().
669: .  -log_mpe [filename] - Creates a logfile viewable by the utility Jumpshot (in MPICH distribution)
670: -  -check_pointer_intensity 0,1,2 - if pointers are checked for validity (debug version only), using 0 will result in faster code

672:     Only one of -log_trace, -log_view, -log_view, -log_all, -log, or -log_mpe may be used at a time

674:    Options Database Keys for SAWs:
675: +  -saws_port <portnumber> - port number to publish SAWs data, default is 8080
676: .  -saws_port_auto_select - have SAWs select a new unique port number where it publishes the data, the URL is printed to the screen
677:                             this is useful when you are running many jobs that utilize SAWs at the same time
678: .  -saws_log <filename> - save a log of all SAWs communication
679: .  -saws_https <certificate file> - have SAWs use HTTPS instead of HTTP
680: -  -saws_root <directory> - allow SAWs to have access to the given directory to search for requested resources and files

682:    Environmental Variables:
683: +   PETSC_TMP - alternative tmp directory
684: .   PETSC_SHARED_TMP - tmp is shared by all processes
685: .   PETSC_NOT_SHARED_TMP - each process has its own private tmp
686: .   PETSC_VIEWER_SOCKET_PORT - socket number to use for socket viewer
687: -   PETSC_VIEWER_SOCKET_MACHINE - machine to use for socket viewer to connect to


690:    Level: beginner

692:    Notes:
693:    If for some reason you must call MPI_Init() separately, call
694:    it before PetscInitialize().

696:    Fortran Version:
697:    In Fortran this routine has the format
698: $       call PetscInitialize(file,ierr)

700: +   ierr - error return code
701: -  file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use PETSC_NULL_CHARACTER to not check for
702:           code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files

704:    Important Fortran Note:
705:    In Fortran, you MUST use PETSC_NULL_CHARACTER to indicate a
706:    null character string; you CANNOT just use NULL as
707:    in the C version. See Users-Manual: Chapter 11 PETSc for Fortran Users for details.

709:    If your main program is C but you call Fortran code that also uses PETSc you need to call PetscInitializeF