Actual source code: pinit.c

petsc-master 2019-06-22
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: PETSC_INTERN PetscErrorCode PetscLogInitialize(void);
 11: PETSC_INTERN PetscErrorCode PetscLogFinalize(void);
 12: #endif

 14: #if defined(PETSC_SERIALIZE_FUNCTIONS)
 15: PETSC_INTERN PetscFPT PetscFPTData;
 16: PetscFPT PetscFPTData = 0;
 17: #endif

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

 24: PETSC_INTERN FILE *petsc_history;

 26: PETSC_INTERN PetscErrorCode PetscInitialize_DynamicLibraries(void);
 27: PETSC_INTERN PetscErrorCode PetscFinalize_DynamicLibraries(void);
 28: PETSC_INTERN PetscErrorCode PetscFunctionListPrintAll(void);
 29: PETSC_INTERN PetscErrorCode PetscSequentialPhaseBegin_Private(MPI_Comm,int);
 30: PETSC_INTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm,int);
 31: PETSC_INTERN PetscErrorCode PetscCloseHistoryFile(FILE**);

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

 36: PetscMPIInt Petsc_Counter_keyval   = MPI_KEYVAL_INVALID;
 37: PetscMPIInt Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID;
 38: PetscMPIInt Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID;
 39: PetscMPIInt Petsc_ShmComm_keyval   = MPI_KEYVAL_INVALID;

 41: /*
 42:      Declare and set all the string names of the PETSc enums
 43: */
 44: const char *const PetscBools[]     = {"FALSE","TRUE","PetscBool","PETSC_",0};
 45: const char *const PetscCopyModes[] = {"COPY_VALUES","OWN_POINTER","USE_POINTER","PetscCopyMode","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: PETSC_INTERN PetscErrorCode  PetscOptionsCheckInitial_Components(void)
 64: {
 65:   PetscBool      flg;

 69:   PetscOptionsHasHelp(NULL,&flg);
 70:   if (flg) {
 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 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 Julia without the problem of trying to initialize MPI more than once.

 94:      Developer Note: Turns off PETSc signal handling to allow Julia to manage signals

 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);if (ierr) return ierr;
106:   PetscPopSignalHandler();
107:   PetscBeganMPI = PETSC_FALSE;
108:   PetscFunctionReturn(ierr);
109: }

111: /*
112:       Used by 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: PETSC_INTERN 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_DelComm_Shm(MPI_Comm,PetscMPIInt,void *,void *);

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

377: PetscMPIInt PETSC_MPI_ERROR_CLASS,PETSC_MPI_ERROR_CODE;

379: PETSC_INTERN int  PetscGlobalArgc;
380: PETSC_INTERN char **PetscGlobalArgs;
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 \n            and Peter Brune and Kris Buschelman and Lisandro Dalcin and\n            Victor Eijkhout and William D. Gropp and Dmitry Karpeyev and\n            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.11},\n  Institution = {Argonne National Laboratory},\n  Year = {2019}\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: static char programname[PETSC_MAX_PATH_LEN] = ""; /* HP includes entire path in name */

398: PetscErrorCode  PetscSetProgramName(const char name[])
399: {

403:   PetscStrncpy(programname,name,PETSC_MAX_PATH_LEN);
404:   return(0);
405: }

407: /*@C
408:     PetscGetProgramName - Gets the name of the running program.

410:     Not Collective

412:     Input Parameter:
413: .   len - length of the string name

415:     Output Parameter:
416: .   name - the name of the running program

418:    Level: advanced

420:     Notes:
421:     The name of the program is copied into the user-provided character
422:     array of length len.  On some machines the program name includes
423:     its entire path, so one should generally set len >= PETSC_MAX_PATH_LEN.
424: @*/
425: PetscErrorCode  PetscGetProgramName(char name[],size_t len)
426: {

430:    PetscStrncpy(name,programname,len);
431:   return(0);
432: }

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

438:    Not Collective

440:    Output Parameters:
441: +  argc - count of number of command line arguments
442: -  args - the command line arguments

444:    Level: intermediate

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

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

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

454: @*/
455: PetscErrorCode  PetscGetArgs(int *argc,char ***args)
456: {
458:   if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
459:   *argc = PetscGlobalArgc;
460:   *args = PetscGlobalArgs;
461:   return(0);
462: }

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

468:    Not Collective

470:    Output Parameters:
471: .  args - the command line arguments

473:    Level: intermediate

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

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

480: @*/
481: PetscErrorCode  PetscGetArguments(char ***args)
482: {
483:   PetscInt       i,argc = PetscGlobalArgc;

487:   if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
488:   if (!argc) {*args = NULL; return(0);}
489:   PetscMalloc1(argc,args);
490:   for (i=0; i<argc-1; i++) {
491:     PetscStrallocpy(PetscGlobalArgs[i+1],&(*args)[i]);
492:   }
493:   (*args)[argc-1] = NULL;
494:   return(0);
495: }

497: /*@C
498:    PetscFreeArguments - Frees the memory obtained with PetscGetArguments()

500:    Not Collective

502:    Output Parameters:
503: .  args - the command line arguments

505:    Level: intermediate

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

509: @*/
510: PetscErrorCode  PetscFreeArguments(char **args)
511: {
512:   PetscInt       i = 0;

516:   if (!args) return(0);
517:   while (args[i]) {
518:     PetscFree(args[i]);
519:     i++;
520:   }
521:   PetscFree(args);
522:   return(0);
523: }

525: #if defined(PETSC_HAVE_SAWS)
526: #include <petscconfiginfo.h>

528: PETSC_INTERN PetscErrorCode PetscInitializeSAWs(const char help[])
529: {
530:   if (!PetscGlobalRank) {
531:     char           cert[PETSC_MAX_PATH_LEN],root[PETSC_MAX_PATH_LEN],*intro,programname[64],*appline,*options,version[64];
532:     int            port;
533:     PetscBool      flg,rootlocal = PETSC_FALSE,flg2,selectport = PETSC_FALSE;
534:     size_t         applinelen,introlen;
536:     char           sawsurl[256];

538:     PetscOptionsHasName(NULL,NULL,"-saws_log",&flg);
539:     if (flg) {
540:       char  sawslog[PETSC_MAX_PATH_LEN];

542:       PetscOptionsGetString(NULL,NULL,"-saws_log",sawslog,PETSC_MAX_PATH_LEN,NULL);
543:       if (sawslog[0]) {
544:         PetscStackCallSAWs(SAWs_Set_Use_Logfile,(sawslog));
545:       } else {
546:         PetscStackCallSAWs(SAWs_Set_Use_Logfile,(NULL));
547:       }
548:     }
549:     PetscOptionsGetString(NULL,NULL,"-saws_https",cert,PETSC_MAX_PATH_LEN,&flg);
550:     if (flg) {
551:       PetscStackCallSAWs(SAWs_Set_Use_HTTPS,(cert));
552:     }
553:     PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select",&selectport,NULL);
554:     if (selectport) {
555:         PetscStackCallSAWs(SAWs_Get_Available_Port,(&port));
556:         PetscStackCallSAWs(SAWs_Set_Port,(port));
557:     } else {
558:       PetscOptionsGetInt(NULL,NULL,"-saws_port",&port,&flg);
559:       if (flg) {
560:         PetscStackCallSAWs(SAWs_Set_Port,(port));
561:       }
562:     }
563:     PetscOptionsGetString(NULL,NULL,"-saws_root",root,PETSC_MAX_PATH_LEN,&flg);
564:     if (flg) {
565:       PetscStackCallSAWs(SAWs_Set_Document_Root,(root));
566:       PetscStrcmp(root,".",&rootlocal);
567:     } else {
568:       PetscOptionsHasName(NULL,NULL,"-saws_options",&flg);
569:       if (flg) {
570:         PetscStrreplace(PETSC_COMM_WORLD,"${PETSC_DIR}/share/petsc/saws",root,PETSC_MAX_PATH_LEN);
571:         PetscStackCallSAWs(SAWs_Set_Document_Root,(root));
572:       }
573:     }
574:     PetscOptionsHasName(NULL,NULL,"-saws_local",&flg2);
575:     if (flg2) {
576:       char jsdir[PETSC_MAX_PATH_LEN];
577:       if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"-saws_local option requires -saws_root option");
578:       PetscSNPrintf(jsdir,PETSC_MAX_PATH_LEN,"%s/js",root);
579:       PetscTestDirectory(jsdir,'r',&flg);
580:       if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_READ,"-saws_local option requires js directory in root directory");
581:       PetscStackCallSAWs(SAWs_Push_Local_Header,());
582:     }
583:     PetscGetProgramName(programname,64);
584:     PetscStrlen(help,&applinelen);
585:     introlen   = 4096 + applinelen;
586:     applinelen += 1024;
587:     PetscMalloc(applinelen,&appline);
588:     PetscMalloc(introlen,&intro);

590:     if (rootlocal) {
591:       PetscSNPrintf(appline,applinelen,"%s.c.html",programname);
592:       PetscTestFile(appline,'r',&rootlocal);
593:     }
594:     PetscOptionsGetAll(NULL,&options);
595:     if (rootlocal && help) {
596:       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);
597:     } else if (help) {
598:       PetscSNPrintf(appline,applinelen,"<center>Running %s %s</center><br><center><pre>%s</pre></center><br>",programname,options,help);
599:     } else {
600:       PetscSNPrintf(appline,applinelen,"<center> Running %s %s</center><br>\n",programname,options);
601:     }
602:     PetscFree(options);
603:     PetscGetVersion(version,sizeof(version));
604:     PetscSNPrintf(intro,introlen,"<body>\n"
605:                                     "<center><h2> <a href=\"https://www.mcs.anl.gov/petsc\">PETSc</a> Application Web server powered by <a href=\"https://bitbucket.org/saws/saws\">SAWs</a> </h2></center>\n"
606:                                     "<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"
607:                                     "%s",version,petscconfigureoptions,appline);
608:     PetscStackCallSAWs(SAWs_Push_Body,("index.html",0,intro));
609:     PetscFree(intro);
610:     PetscFree(appline);
611:     if (selectport) {
612:       PetscBool silent;

614:       SAWs_Initialize();
615:       /* another process may have grabbed the port so keep trying */
616:       while (ierr) {
617:         PetscStackCallSAWs(SAWs_Get_Available_Port,(&port));
618:         PetscStackCallSAWs(SAWs_Set_Port,(port));
619:         SAWs_Initialize();
620:       }

622:       PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select_silent",&silent,NULL);
623:       if (!silent) {
624:         PetscStackCallSAWs(SAWs_Get_FullURL,(sizeof(sawsurl),sawsurl));
625:         PetscPrintf(PETSC_COMM_WORLD,"Point your browser to %s for SAWs\n",sawsurl);
626:       }
627:     } else {
628:       PetscStackCallSAWs(SAWs_Initialize,());
629:     }
630:     PetscCitationsRegister("@TechReport{ saws,\n"
631:                                   "  Author = {Matt Otten and Jed Brown and Barry Smith},\n"
632:                                   "  Title  = {Scientific Application Web Server (SAWs) Users Manual},\n"
633:                                   "  Institution = {Argonne National Laboratory},\n"
634:                                   "  Year   = 2013\n}\n",NULL);
635:   }
636:   return(0);
637: }
638: #endif

640: #if defined(PETSC_HAVE_ADIOS)
641: #include <adios.h>
642: #include <adios_read.h>
643: int64_t Petsc_adios_group;
644: #endif
645: #if defined(PETSC_HAVE_ADIOS2)
646: #include <adios2_c.h>
647: #endif
648: #if defined(PETSC_HAVE_OPENMP)
649: #include <omp.h>
650: PetscInt PetscNumOMPThreads;
651: #endif

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

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

661:    Input Parameters:
662: +  argc - count of number of command line arguments
663: .  args - the command line arguments
664: .  file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use NULL to not check for
665:           code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files
666: -  help - [optional] Help message to print, use NULL for no message

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

674:    Options Database Keys:
675: +  -help [intro] - prints help method for each option; if intro is given the program stops after printing the introductory help message
676: .  -start_in_debugger [noxterm,dbx,xdb,gdb,...] - Starts program in debugger
677: .  -on_error_attach_debugger [noxterm,dbx,xdb,gdb,...] - Starts debugger when error detected
678: .  -on_error_emacs <machinename> - causes emacsclient to jump to error file
679: .  -on_error_abort - calls abort() when error detected (no traceback)
680: .  -on_error_mpiabort - calls MPI_abort() when error detected
681: .  -error_output_stderr - prints error messages to stderr instead of the default stdout
682: .  -error_output_none - does not print the error messages (but handles errors in the same way as if this was not called)
683: .  -debugger_nodes [node1,node2,...] - Indicates nodes to start in debugger
684: .  -debugger_pause [sleeptime] (in seconds) - Pauses debugger
685: .  -stop_for_debugger - Print message on how to attach debugger manually to
686:                         process and wait (-debugger_pause) seconds for attachment
687: .  -malloc - Indicates use of PETSc error-checking malloc (on by default for debug version of libraries)
688: .  -malloc no - Indicates not to use error-checking malloc
689: .  -malloc_debug - check for memory corruption at EVERY malloc or free
690: .  -malloc_dump - prints a list of all unfreed memory at the end of the run
691: .  -malloc_test - like -malloc_dump -malloc_debug, but only active for debugging builds
692: .  -fp_trap - Stops on floating point exceptions (Note that on the
693:               IBM RS6000 this slows code by at least a factor of 10.)
694: .  -no_signal_handler - Indicates not to trap error signals
695: .  -shared_tmp - indicates /tmp directory is shared by all processors
696: .  -not_shared_tmp - each processor has own /tmp
697: .  -tmp - alternative name of /tmp directory
698: .  -get_total_flops - returns total flops done by all processors
699: -  -memory_view - Print memory usage at end of run

701:    Options Database Keys for Profiling:
702:    See Users-Manual: Chapter 13 Profiling for details.
703: +  -info <optional filename> - Prints verbose information to the screen
704: .  -info_exclude <null,vec,mat,pc,ksp,snes,ts> - Excludes some of the verbose messages
705: .  -log_sync - Enable barrier synchronization for all events. This option is useful to debug imbalance within each event,
706:         however it slows things down and gives a distorted view of the overall runtime.
707: .  -log_trace [filename] - Print traces of all PETSc calls to the screen (useful to determine where a program
708:         hangs without running in the debugger).  See PetscLogTraceBegin().
709: .  -log_view [:filename:format] - Prints summary of flop and timing information to screen or file, see PetscLogView().
710: .  -log_summary [filename] - (Deprecated, use -log_view) Prints summary of flop and timing information to screen. If the filename is specified the
711:         summary is written to the file.  See PetscLogView().
712: .  -log_exclude: <vec,mat,pc,ksp,snes> - excludes subset of object classes from logging
713: .  -log_all [filename] - Logs extensive profiling information  See PetscLogDump().
714: .  -log [filename] - Logs basic profiline information  See PetscLogDump().
715: .  -log_mpe [filename] - Creates a logfile viewable by the utility Jumpshot (in MPICH distribution)
716: .  -viewfromoptions on,off - Enable or disable XXXSetFromOptions() calls, for applications with many small solves turn this off
717: -  -check_pointer_intensity 0,1,2 - if pointers are checked for validity (debug version only), using 0 will result in faster code

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

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

729:    Environmental Variables:
730: +   PETSC_TMP - alternative tmp directory
731: .   PETSC_SHARED_TMP - tmp is shared by all processes
732: .   PETSC_NOT_SHARED_TMP - each process has its own private tmp
733: .   PETSC_VIEWER_SOCKET_PORT - socket number to use for socket viewer
734: -   PETSC_VIEWER_SOCKET_MACHINE - machine to use for socket viewer to connect to


737:    Level: beginner

739:    Notes:
740:    If for some reason you must call MPI_Init() separately, call
741:    it before PetscInitialize().

743:    Fortran Version:
744:    In Fortran this routine has the format
745: $       call PetscInitialize(file,ierr)

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

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

756:    If your main program is C but you call Fortran code that also uses PETSc you need to call PetscInitializeFortran() soon after
757:    calling PetscInitialize().

759: .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscInitializeNoArguments()

761: @*/
762: PetscErrorCode