Actual source code: verboseinfo.c

petsc-3.13.0 2020-03-29
Report Typos and Errors
  1: /*
  2:       PetscInfo() is contained in a different file from the other profiling to
  3:    allow it to be replaced at link time by an alternative routine.
  4: */
  5:  #include <petsc/private/petscimpl.h>

  7: /*
  8:   The next set of variables determine which, if any, PetscInfo() calls are used.
  9:   If PetscLogPrintInfo is false, no info messages are printed.

 11:   If PetscInfoFlags[OBJECT_CLASSID - PETSC_SMALLEST_CLASSID] is zero, no messages related
 12:   to that object are printed. OBJECT_CLASSID is, for example, MAT_CLASSID.
 13:   Note for developers: the PetscInfoFlags array is currently 160 entries large, to ensure headroom. Perhaps it is worth
 14:   dynamically allocating this array intelligently rather than just some big number.

 16:   PetscInfoFilename determines where PetscInfo() output is piped.
 17:   PetscInfoClassnames holds a char array of classes which are filtered out/for in PetscInfo() calls.
 18: */
 19: const char * const        PetscInfoCommFlags[] = {"all", "no_self", "only_self", "PetscInfoCommFlag", "PETSC_INFO_COMM_", 0};
 20: static PetscBool          PetscInfoClassnamesLocked = PETSC_FALSE, PetscInfoInvertClasses = PETSC_FALSE;
 21: static char               **PetscInfoClassnames = NULL;
 22: static char               *PetscInfoFilename = NULL;
 23: static PetscInt           PetscInfoNumClasses = -1;
 24: static PetscInfoCommFlag  PetscInfoCommFilter = PETSC_INFO_COMM_ALL;
 25: static int                PetscInfoFlags[]  = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 26:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 27:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 28:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 29:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 30:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 31:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 32:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 33:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 34:                                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
 35: PetscBool                 PetscLogPrintInfo = PETSC_FALSE, PetscInfoSetUp = PETSC_FALSE;
 36: FILE                      *PetscInfoFile = NULL;

 38: /*@
 39:     PetscInfoEnabled - Checks whether a given OBJECT_CLASSID is allowed to print using PetscInfo()

 41:     Not Collective

 43:     Input Parameters:
 44: .   classid - PetscClassid retrieved from a PetscObject e.g. VEC_CLASSID

 46:     Output Parameter:
 47: .   enabled - PetscBool indicating whether this classid is allowed to print

 49:     Notes:
 50:     Use PETSC_SMALLEST_CLASSID to check if "sys" PetscInfo() calls are enabled. When PETSc is configured with debugging
 51:     support this function checks if classid >= PETSC_SMALLEST_CLASSID, otherwise it assumes valid classid.

 53:     Level: advanced

 55: .seealso: PetscInfo(), PetscInfoAllow(), PetscInfoGetInfo(), PetscObjectGetClassid()
 56: @*/
 57: PetscErrorCode PetscInfoEnabled(PetscClassId classid, PetscBool *enabled)
 58: {
 60: #if defined(PETSC_USE_DEBUG)
 61:   if (classid < PETSC_SMALLEST_CLASSID) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Classid (current: %d) must be equal to or greater than PETSC_SMALLEST_CLASSID", classid);
 62: #endif
 63:   *enabled = (PetscBool) (PetscLogPrintInfo && PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID]);
 64:   return(0);
 65: }

 67: /*@
 68:     PetscInfoAllow - Enables/disables PetscInfo() messages

 70:     Not Collective

 72:     Input Parameter:
 73: .   flag - PETSC_TRUE or PETSC_FALSE

 75:     Level: advanced

 77: .seealso: PetscInfo(), PetscInfoEnabled(), PetscInfoGetInfo(), PetscInfoSetFromOptions()
 78: @*/
 79: PetscErrorCode PetscInfoAllow(PetscBool flag)
 80: {
 82:   PetscLogPrintInfo = flag;
 83:   return(0);
 84: }

 86: /*@C
 87:     PetscInfoSetFile - Sets the printing destination for all PetscInfo() calls

 89:     Not Collective

 91:     Input Parameter:
 92: +   filename - Name of the file where PetscInfo() will print to
 93: -   mode - Write mode passed to PetscFOpen()

 95:     Notes:
 96:     Use filename=NULL to set PetscInfo() to write to PETSC_STDOUT.

 98:     Level: advanced

100: .seealso: PetscInfo(), PetscInfoSetFile(), PetscInfoSetFromOptions(), PetscFOpen()
101: @*/
102: PetscErrorCode PetscInfoSetFile(const char filename[], const char mode[])
103: {
104:   char            fname[PETSC_MAX_PATH_LEN], tname[11];
105:   PetscMPIInt     rank;
106:   PetscErrorCode  ierr;

109:   if (!PetscInfoFile) PetscInfoFile = PETSC_STDOUT;
110:   PetscFree(PetscInfoFilename);
111:   if (filename) {
112:     PetscBool  oldflag;
114:     PetscFixFilename(filename, fname);
115:     PetscStrallocpy(fname, &PetscInfoFilename);
116:     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
117:     sprintf(tname, ".%d", rank);
118:     PetscStrcat(fname, tname);
119:     oldflag = PetscLogPrintInfo; PetscLogPrintInfo = PETSC_FALSE;
120:     PetscFOpen(MPI_COMM_SELF, fname, mode, &PetscInfoFile);
121:     PetscLogPrintInfo = oldflag;
122:     /* PetscFOpen will write to PETSC_STDOUT and not PetscInfoFile here, so we disable the PetscInfo call inside it, and
123:      call it afterwards so that it actually writes to file */
124:     PetscInfo1(NULL, "Opened PetscInfo file %s\n", fname);
125:   }
126:   return(0);
127: }

129: /*@C
130:     PetscInfoGetFile - Gets the name and FILE pointer of the file where PetscInfo() prints to

132:     Not Collective

134:     Output Parameters:
135: +   filename - The name of the output file
136: -   InfoFile - The FILE pointer for the output file

138:     Level: advanced

140:     Note:
141:     This routine allocates and copies the filename so that the filename survives PetscInfoDestroy(). The user is
142:     therefore responsible for freeing the allocated filename pointer afterwards.

144:     Fortran Note:
145:     This routine is not supported in Fortran.

147: .seealso: PetscInfo(), PetscInfoSetFile(), PetscInfoSetFromOptions(), PetscInfoDestroy()
148: @*/
149: PetscErrorCode PetscInfoGetFile(char **filename, FILE **InfoFile)
150: {
151:   PetscErrorCode  ierr;

156:   PetscStrallocpy(PetscInfoFilename, filename);
157:   *InfoFile = PetscInfoFile;
158:   return(0);
159: }

161: /*@C
162:     PetscInfoSetClasses - Sets the classes which PetscInfo() is filtered for/against

164:     Not Collective

166:     Input Parameters:
167: +   exclude - Whether or not to invert the filter, i.e. if exclude is true, PetscInfo() will print from every class that
168:     is NOT one of the classes specified
169: .   N - Number of classes to filter for (size of classnames)
170: -   classnames - String array containing the names of classes to filter for, e.g. "vec"

172:     Notes:
173:     Not for use in Fortran

175:     This function CANNOT be called after PetscInfoGetClass() or PetscInfoProcessClass() has been called.

177:     Names in the classnames list should correspond to the names returned by PetscObjectGetClassName().

179:     This function only sets the list of class names.
180:     The actual filtering is deferred to PetscInfoProcessClass(), except of sys which is processed right away.
181:     The reason for this is that we need to set the list of included/excluded classes before their classids are known.
182:     Typically the classid is assigned and PetscInfoProcessClass() called in <Class>InitializePackage() (e.g. VecInitializePackage()).

184:     Level: developer

186: .seealso: PetscInfo(), PetscInfoGetClass(), PetscInfoProcessClass(), PetscInfoSetFromOptions(), PetscStrToArray(), PetscObjectGetName()
187: @*/
188: PetscErrorCode PetscInfoSetClasses(PetscBool exclude, PetscInt N, const char *const *classnames)
189: {
190:   PetscErrorCode  ierr;

193:   if (PetscInfoClassnamesLocked) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscInfoSetClasses() cannot be called after PetscInfoGetClass() or PetscInfoProcessClass()");
194:   PetscStrNArrayDestroy(PetscInfoNumClasses, &PetscInfoClassnames);
195:   PetscStrNArrayallocpy(N, classnames, &PetscInfoClassnames);
196:   PetscInfoNumClasses = N;
197:   PetscInfoInvertClasses = exclude;
198:   {
199:     /* Process sys class right away */
200:     PetscClassId  sysclassid = PETSC_SMALLEST_CLASSID;
201:     PetscInfoProcessClass("sys", 1, &sysclassid);
202:   }
203:   PetscInfoSetUp = PETSC_TRUE;
204:   return(0);
205: }

207: /*@C
208:     PetscInfoGetClass - Indicates whether the provided classname is marked as a filter in PetscInfo() as set by PetscInfoSetClasses()

210:     Not Collective

212:     Input Paramater:
213: .   classname - Name of the class to search for

215:     Output Parameter:
216: .   found - PetscBool indicating whether the classname was found

218:     Notes:
219:     Use PetscObjectGetName() to retrieve an appropriate classname

221:     Level: developer

223: .seealso: PetscInfo(), PetscInfoSetClasses(), PetscInfoSetFromOptions(), PetscObjectGetName()
224: @*/
225: PetscErrorCode PetscInfoGetClass(const char *classname, PetscBool *found)
226: {
227:   PetscInt        idx;
228:   PetscErrorCode  ierr;

232:   PetscEListFind(PetscInfoNumClasses, (const char *const *) PetscInfoClassnames, classname ? classname : "sys", &idx, found);
233:   PetscInfoClassnamesLocked = PETSC_TRUE;
234:   return(0);
235: }

237: /*@
238:     PetscInfoGetInfo - Returns the current state of several important flags for PetscInfo()

240:     Not Collective

242:     Output Parameters:
243: +   infoEnabled - PETSC_TRUE if PetscInfoAllow(PETSC_TRUE) has been called
244: .   exclude - PETSC_TRUE if the class filtering for PetscInfo() is inverted
245: .   locked - PETSC_TRUE if the list of classes to filter for has been locked
246: -   commSelfFlag - Enum indicating whether PetscInfo() will print for communicators of size 1, any size != 1, or all
247:     communicators

249:     Notes:
250:     Initially commSelfFlag = PETSC_INFO_COMM_ALL

252:     Level: developer

254: .seealso: PetscInfo(), PetscInfoAllow(), PetscInfoSetFilterCommSelf, PetscInfoSetFromOptions()
255: @*/
256: PetscErrorCode PetscInfoGetInfo(PetscBool *infoEnabled, PetscBool *setup, PetscBool *exclude, PetscBool *locked, PetscInfoCommFlag *commSelfFlag)
257: {
259:   if (infoEnabled)  *infoEnabled  = PetscLogPrintInfo;
260:   if (setup)        *setup        = PetscInfoSetUp;
261:   if (exclude)      *exclude      = PetscInfoInvertClasses;
262:   if (locked)       *locked       = PetscInfoClassnamesLocked;
263:   if (commSelfFlag) *commSelfFlag = PetscInfoCommFilter;
264:   return(0);
265: }

267: /*@C
268:     PetscInfoProcessClass - Activates or deactivates a class based on the filtering status of PetscInfo()

270:     Not Collective

272:     Input Parameters:
273: +   classname - Name of the class to activate/deactivate PetscInfo() for
274: .   numClassID - Number of entries in classIDs
275: -   classIDs - Array containing all of the PetscClassids associated with classname

277:     Level: developer

279: .seealso: PetscInfo(), PetscInfoActivateClass(), PetscInfoDeactivateClass(), PetscInfoSetFromOptions()
280: @*/
281: PetscErrorCode PetscInfoProcessClass(const char classname[], PetscInt numClassID, PetscClassId classIDs[])
282: {
283:   PetscInt        i;
284:   PetscBool       enabled, exclude, found, opt, pkg;
285:   char            logList[256];
286:   PetscErrorCode  ierr;

290:   PetscInfoGetInfo(&enabled, NULL, &exclude, NULL, NULL);
291:   /* -info_exclude is DEPRECATED */
292:   PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);
293:   if (opt) {
294:     PetscStrInList(classname,logList,',',&pkg);
295:     if (pkg) {
296:       for (i = 0; i < numClassID; ++i) {
297:         PetscInfoDeactivateClass(classIDs[i]);
298:       }
299:     }
300:   }
301:   PetscInfoGetClass(classname, &found);
302:   if ((found && exclude) || (!found && !exclude)) {
303:     if (PetscInfoNumClasses > 0) {
304:       /* Check if -info was called empty */
305:       for (i = 0; i < numClassID; ++i) {
306:         PetscInfoDeactivateClass(classIDs[i]);
307:       }
308:     }
309:   } else {
310:     for (i = 0; i < numClassID; ++i) {
311:       PetscInfoActivateClass(classIDs[i]);
312:     }
313:   }
314:   return(0);
315: }

317: /*@
318:     PetscInfoSetFilterCommSelf - Sets PetscInfoCommFlag enum to determine communicator filtering for PetscInfo()

320:     Not Collective

322:     Input Parameter:
323: .   commSelfFlag - Enum value indicating method with which to filter PetscInfo() based on the size of the communicator of the object calling PetscInfo()

325:     Level: advanced

327: .seealso: PetscInfo(), PetscInfoGetInfo()
328: @*/
329: PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag commSelfFlag)
330: {
332:   PetscInfoCommFilter = commSelfFlag;
333:   return(0);
334: }

336: /*@
337:     PetscInfoSetFromOptions - Configure PetscInfo() using command line options, enabling or disabling various calls to PetscInfo()

339:     Not Collective

341:     Input Parameter:
342: .   options - Options database, use NULL for default global database

344:     Options Database Keys:
345: .   -info [filename][:[~]<list,of,classnames>[:[~]self]] - specify which informative messages are printed, See PetscInfo().

347:     Notes:
348:     This function is called automatically during PetscInitialize() so users usually do not need to call it themselves.

350:     Level: advanced

352: .seealso: PetscInfo(), PetscInfoAllow(), PetscInfoSetFile(), PetscInfoSetClasses(), PetscInfoSetFilterCommSelf(), PetscInfoDestroy()
353: @*/
354: PetscErrorCode PetscInfoSetFromOptions(PetscOptions options)
355: {
356:   PetscToken         tok;
357:   char               optstring[PETSC_MAX_PATH_LEN], *loc0_ = NULL, *loc1_ = NULL, *loc2_ = NULL;
358:   char               **loc1_array = NULL;
359:   PetscBool          set, loc1_invert = PETSC_FALSE, loc2_invert = PETSC_FALSE, foundSelf = PETSC_FALSE;
360:   size_t             size_loc0_ = 0, size_loc1_ = 0, size_loc2_ = 0;
361:   int                nLoc1_ = 0;
362:   PetscInfoCommFlag  commSelfFlag = PETSC_INFO_COMM_ALL;
363:   PetscErrorCode     ierr;

366:   PetscOptionsDeprecated_Private(NULL,"-info_exclude", NULL, "3.13", "Use -info instead");
367:   PetscOptionsGetString(options, NULL, "-info", optstring, PETSC_MAX_PATH_LEN, &set);
368:   if (set) {
369:     /* Allow sys class to be processed as part of setup */
370:     PetscInfoSetUp = PETSC_TRUE;
371:     PetscInfoAllow(PETSC_TRUE);
372:     PetscTokenCreate(optstring, ':', &tok);
373:     PetscTokenFind(tok, &loc0_);
374:     PetscTokenFind(tok, &loc1_);
375:     PetscTokenFind(tok, &loc2_);
376:     if (loc1_) {
377:       PetscStrcmp("self", (const char *) loc1_, &foundSelf);
378:       if (foundSelf) {
379:         /* side effect of PetscTokenFind() if tokens are next to each other, i.e. str="foo::bar", instead of "foo" "" "bar", returns "foo" "bar" "NULL" */
380:         loc2_ = loc1_;
381:         loc1_ = NULL;
382:       } else {
383:         if (*loc1_ == '~') {
384:           loc1_invert = PETSC_TRUE;
385:           ++loc1_;
386:         }
387:       }
388:     }
389:     if (loc2_) {
390:       if (*loc2_ == '~') {
391:         loc2_invert = PETSC_TRUE;
392:         ++loc2_;
393:       }
394:     }
395:     PetscStrlen(loc0_, &size_loc0_);
396:     PetscStrlen(loc1_, &size_loc1_);
397:     PetscStrlen(loc2_, &size_loc2_);
398:     if (size_loc1_) {
399:       PetscStrtolower(loc1_);
400:       PetscStrToArray((const char *) loc1_, ',',(int *) &nLoc1_, &loc1_array);
401:     }
402:     if (size_loc2_) {
403:       PetscStrtolower(loc2_);
404:       PetscStrcmp("self", (const char *) loc2_, &foundSelf);
405:       if (foundSelf) {
406:         if (loc2_invert) {
407:           commSelfFlag = PETSC_INFO_COMM_NO_SELF;
408:         } else {
409:           commSelfFlag = PETSC_INFO_COMM_ONLY_SELF;
410:         }
411:       }
412:     }
413:     PetscInfoSetFile((const char *) size_loc0_ ? loc0_ : NULL, "w");
414:     PetscInfoSetClasses(loc1_invert,(PetscInt) nLoc1_, (const char *const *) loc1_array);
415:     PetscInfoSetFilterCommSelf(commSelfFlag);
416:     PetscStrToArrayDestroy(nLoc1_, loc1_array);
417:     PetscTokenDestroy(&tok);
418:   }
419:   return(0);
420: }

422: /*@
423:   PetscInfoDestroy - Destroys and resets internal PetscInfo() data structures.

425:   Not Collective

427:   Notes:
428:   This is automatically called in PetscFinalize(). Useful for changing filters mid-program, or culling subsequent
429:   PetscInfo() calls down the line.

431:   Level: developer

433: .seealso: PetscInfo(), PetscInfoSetFromOptions()
434: @*/
435: PetscErrorCode PetscInfoDestroy(void)
436: {
437:   PetscErrorCode  ierr;
438:   int             err;

441:   PetscInfoAllow(PETSC_FALSE);
442:   PetscStrNArrayDestroy(PetscInfoNumClasses, &PetscInfoClassnames);
443:   err  = fflush(PetscInfoFile);
444:   if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
445:   if (PetscInfoFilename) {
446:     PetscFClose(MPI_COMM_SELF, PetscInfoFile);
447:   }
448:   PetscFree(PetscInfoFilename);
449:   memset(PetscInfoFlags, 1, (size_t) 160*sizeof(PetscInfoFlags[0]));
450:   PetscInfoClassnamesLocked = PETSC_FALSE;
451:   PetscInfoInvertClasses = PETSC_FALSE;
452:   PetscInfoNumClasses = -1;
453:   PetscInfoCommFilter = PETSC_INFO_COMM_ALL;
454:   PetscInfoSetUp = PETSC_FALSE;
455:   return(0);
456: }

458: /*@
459:   PetscInfoDeactivateClass - Deactivates PetscInfo() messages for a PETSc object class.

461:   Not Collective

463:   Input Parameter:
464: . classid - The object class,  e.g., MAT_CLASSID, SNES_CLASSID, etc.

466:   Notes:
467:   One can pass 0 to deactivate all messages that are not associated with an object.

469:   Level: developer

471: .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow(), PetscInfoSetFromOptions()
472: @*/
473: PetscErrorCode  PetscInfoDeactivateClass(PetscClassId classid)
474: {
476:   if (!classid) classid = PETSC_SMALLEST_CLASSID;
477:   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 0;
478:   return(0);
479: }

481: /*@
482:   PetscInfoActivateClass - Activates PetscInfo() messages for a PETSc object class.

484:   Not Collective

486:   Input Parameter:
487: . classid - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc.

489:   Notes:
490:   One can pass 0 to activate all messages that are not associated with an object.

492:   Level: developer

494: .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow(), PetscInfoSetFromOptions()
495: @*/
496: PetscErrorCode  PetscInfoActivateClass(PetscClassId classid)
497: {
499:   if (!classid) classid = PETSC_SMALLEST_CLASSID;
500:   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 1;
501:   return(0);
502: }

504: /*
505:    If the option -history was used, then all printed PetscInfo()
506:   messages are also printed to the history file, called by default
507:   .petschistory in ones home directory.
508: */
509: PETSC_INTERN FILE *petsc_history;

511: /*MC
512:     PetscInfo - Logs informative data

514:    Synopsis:
515:        #include <petscsys.h>
516:        PetscErrorCode PetscInfo(PetscObject obj, const char message[])
517:        PetscErrorCode PetscInfo1(PetscObject obj, const char formatmessage[],arg1)
518:        PetscErrorCode PetscInfo2(PetscObject obj, const char formatmessage[],arg1,arg2)
519:        ...

521:     Collective on obj

523:     Input Parameter:
524: +   obj - object most closely associated with the logging statement or NULL
525: .   message - logging message
526: .   formatmessage - logging message using standard "printf" format
527: -   arg1, arg2, ... - arguments of the format

529:     Notes:
530:     PetscInfo() prints only from the first processor in the communicator of obj.
531:     If obj is NULL, the PETSC_COMM_SELF communicator is used, i.e. every rank of PETSC_COMM_WORLD prints the message.

533:     Extent of the printed messages can be controlled using the option database key -info as follows.

535: $   -info [filename][:[~]<list,of,classnames>[:[~]self]]

537:     No filename means standard output PETSC_STDOUT is used.

539:     The optional <list,of,classnames> is a comma separated list of enabled classes, e.g. vec,mat,ksp.
540:     If this list is not specified, all classes are enabled.
541:     Prepending the list with ~ means inverted selection, i.e. all classes except the listed are enabled.
542:     A special classname sys relates to PetscInfo() with obj being NULL. 

544:     The optional self keyword specifies that PetscInfo() is enabled only for communicator size = 1 (e.g. PETSC_COMM_SELF), i.e. only PetscInfo() calls which print from every rank of PETSC_COMM_WORLD are enabled.
545:     By contrast, ~self means that PetscInfo() is enabled only for communicator size > 1 (e.g. PETSC_COMM_WORLD), i.e. those PetscInfo() calls which print from every rank of PETSC_COMM_WORLD are disabled.

547:     All classname/self matching is case insensitive. Filename is case sensitive.

549:     Example of Usage:
550: $     Mat A;
551: $     PetscInt alpha;
552: $     ...
553: $     PetscInfo1(A,"Matrix uses parameter alpha=%D\n",alpha);

555:     Options Examples:
556:     Each call of the form
557: $     PetscInfo(obj, msg);
558: $     PetscInfo1(obj, msg, arg1);
559: $     PetscInfo2(obj, msg, arg1, arg2);
560:     is evaluated as follows.
561: $     -info or -info :: prints msg to PETSC_STDOUT, for any obj regardless class or communicator
562: $     -info :mat:self prints msg to PETSC_STDOUT only if class of obj is Mat, and its communicator has size = 1
563: $     -info myInfoFileName:~vec:~self prints msg to file named myInfoFileName, only if the obj's class is NULL or other than Vec, and obj's communicator has size > 1
564: $     -info :sys prints to PETSC_STDOUT only if obj is NULL
565:     Note that
566: $     -info :sys:~self
567:     deactivates all info messages because sys means obj = NULL which implies PETSC_COMM_SELF but ~self filters out everything on PETSC_COMM_SELF.

569:     Fortran Note:
570:     This function does not take the obj argument, there is only the PetscInfo()
571:      version, not PetscInfo1() etc.

573:     Level: intermediate

575: .seealso: PetscInfoAllow(), PetscInfoSetFromOptions()
576: M*/
577: PetscErrorCode  PetscInfo_Private(const char func[],PetscObject obj, const char message[], ...)
578: {
579:   va_list        Argp;
580:   PetscMPIInt    rank = 0,urank,size = 1;
581:   PetscClassId   classid;
582:   PetscBool      enabled = PETSC_FALSE, oldflag;
583:   char           string[8*1024];
585:   size_t         fullLength,len;
586:   int            err;

590:   classid = obj ? obj->classid : PETSC_SMALLEST_CLASSID;
591:   PetscInfoEnabled(classid, &enabled);
592:   if (!enabled) return(0);
594:   if (obj) {
595:     MPI_Comm_rank(obj->comm, &rank);
596:     MPI_Comm_size(obj->comm, &size);
597:   }
598:   /* rank > 0 always jumps out */
599:   if (rank) return(0);
600:   if (!PetscInfoCommFilter && (size < 2)) {
601:     /* If no self printing is allowed, and size too small get out */
602:     return(0);
603:   } else if ((PetscInfoCommFilter == PETSC_INFO_COMM_ONLY_SELF) && (size > 1)) {
604:     /* If ONLY self printing, and size too big, get out */
605:     return(0);
606:   }
607:   /* Mute info messages within this function */
608:   oldflag = PetscLogPrintInfo; PetscLogPrintInfo = PETSC_FALSE;
609:   MPI_Comm_rank(MPI_COMM_WORLD, &urank);
610:   va_start(Argp, message);
611:   sprintf(string, "[%d] %s(): ",urank,func);
612:   PetscStrlen(string, &len);
613:   PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);
614:   PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);
615:   err  = fflush(PetscInfoFile);
616:   if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
617:   if (petsc_history) {
618:     va_start(Argp, message);
619:     (*PetscVFPrintf)(petsc_history, message, Argp);
620:   }
621:   va_end(Argp);
622:   PetscLogPrintInfo = oldflag;
623:   return(0);
624: }