Actual source code: verboseinfo.c

  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_", NULL};
 20: static PetscBool         PetscInfoClassesLocked = PETSC_FALSE, PetscInfoInvertClasses = PETSC_FALSE, PetscInfoClassesSet = 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
 28: static char             *PetscInfoNames[PETSC_STATIC_ARRAY_LENGTH(PetscInfoFlags)] = {NULL};
 29: PetscBool                PetscLogPrintInfo                                         = PETSC_FALSE;
 30: FILE                    *PetscInfoFile                                             = NULL;

 32: /*@
 33:     PetscInfoEnabled - Checks whether a given OBJECT_CLASSID is allowed to print using `PetscInfo()`

 35:     Not Collective

 37:     Input Parameters:
 38: .   classid - `PetscClassid` retrieved from a `PetscObject` e.g. `VEC_CLASSID`

 40:     Output Parameter:
 41: .   enabled - `PetscBool` indicating whether this classid is allowed to print

 43:     Note:
 44:     Use `PETSC_SMALLEST_CLASSID` to check if "sys" `PetscInfo()` calls are enabled. When PETSc is configured with debugging
 45:     support this function checks if classid >= `PETSC_SMALLEST_CLASSID`, otherwise it assumes valid classid.

 47:     Level: advanced

 49: .seealso: `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoGetInfo()`, `PetscObjectGetClassid()`
 50: @*/
 51: PetscErrorCode PetscInfoEnabled(PetscClassId classid, PetscBool *enabled)
 52: {
 55:   *enabled = (PetscBool)(PetscLogPrintInfo && PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID]);
 56:   return 0;
 57: }

 59: /*@
 60:     PetscInfoAllow - Enables/disables `PetscInfo()` messages

 62:     Not Collective

 64:     Input Parameter:
 65: .   flag - `PETSC_TRUE` or `PETSC_FALSE`

 67:     Level: advanced

 69: .seealso: `PetscInfo()`, `PetscInfoEnabled()`, `PetscInfoGetInfo()`, `PetscInfoSetFromOptions()`
 70: @*/
 71: PetscErrorCode PetscInfoAllow(PetscBool flag)
 72: {
 73:   PetscLogPrintInfo = flag;
 74:   return 0;
 75: }

 77: /*@C
 78:     PetscInfoSetFile - Sets the printing destination for all `PetscInfo()` calls

 80:     Not Collective

 82:     Input Parameters:
 83: +   filename - Name of the file where `PetscInfo()` will print to
 84: -   mode - Write mode passed to PetscFOpen()`

 86:     Note:
 87:     Use filename = NULL to set `PetscInfo()` to write to `PETSC_STDOUT`.

 89:     Level: advanced

 91: .seealso: `PetscInfo()`, `PetscInfoSetFile()`, `PetscInfoSetFromOptions()`, `PetscFOpen()`
 92: @*/
 93: PetscErrorCode PetscInfoSetFile(const char filename[], const char mode[])
 94: {
 95:   if (!PetscInfoFile) PetscInfoFile = PETSC_STDOUT;
 96:   PetscFree(PetscInfoFilename);
 97:   if (filename) {
 98:     PetscMPIInt rank;
 99:     char        fname[PETSC_MAX_PATH_LEN], tname[11];

103:     PetscFixFilename(filename, fname);
104:     PetscStrallocpy(fname, &PetscInfoFilename);
105:     MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
106:     PetscSNPrintf(tname, PETSC_STATIC_ARRAY_LENGTH(tname), ".%d", rank);
107:     PetscStrlcat(fname, tname, PETSC_STATIC_ARRAY_LENGTH(fname));
108:     {
109:       const PetscBool oldflag = PetscLogPrintInfo;

111:       PetscLogPrintInfo = PETSC_FALSE;
112:       PetscFOpen(PETSC_COMM_SELF, fname, mode, &PetscInfoFile);
113:       PetscLogPrintInfo = oldflag;
114:       /*
115:         PetscFOpen will write to PETSC_STDOUT and not PetscInfoFile here, so we disable the
116:         PetscInfo call inside it, and call it afterwards so that it actually writes to file
117:       */
118:     }
119:     PetscInfo(NULL, "Opened PetscInfo file %s\n", fname);
120:   }
121:   return 0;
122: }

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

127:     Not Collective; No Fortran Support

129:     Output Parameters:
130: +   filename - The name of the output file
131: -   InfoFile - The FILE pointer for the output file

133:     Level: advanced

135:     Note:
136:     This routine allocates and copies the filename so that the filename survives `PetscInfoDestroy()`. The user is
137:     therefore responsible for freeing the allocated filename pointer afterwards.

139: .seealso: `PetscInfo()`, `PetscInfoSetFile()`, `PetscInfoSetFromOptions()`, `PetscInfoDestroy()`
140: @*/
141: PetscErrorCode PetscInfoGetFile(char **filename, FILE **InfoFile)
142: {
145:   PetscStrallocpy(PetscInfoFilename, filename);
146:   *InfoFile = PetscInfoFile;
147:   return 0;
148: }

150: /*@C
151:     PetscInfoSetClasses - Sets the classes which `PetscInfo()` is filtered for/against

153:     Not Collective

155:     Input Parameters:
156: +   exclude - Whether or not to invert the filter, i.e. if exclude is true, `PetscInfo()` will print from every class that
157:     is NOT one of the classes specified
158: .   n - Number of classes to filter for (size of classnames)
159: -   classnames - String array containing the names of classes to filter for, e.g. "vec"

161:     Notes:
162:     This function CANNOT be called after `PetscInfoGetClass()` or `PetscInfoProcessClass()` has been called.

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

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

171:     Fortran Note:
172:     Not for use in Fortran

174:     Level: developer

176: .seealso: `PetscInfo()`, `PetscInfoGetClass()`, `PetscInfoProcessClass()`, `PetscInfoSetFromOptions()`, `PetscStrToArray()`, `PetscObjectGetName()`
177: @*/
178: PetscErrorCode PetscInfoSetClasses(PetscBool exclude, PetscInt n, const char *const *classnames)
179: {
181:   PetscStrNArrayDestroy(PetscInfoNumClasses, &PetscInfoClassnames);
182:   PetscStrNArrayallocpy(n, classnames, &PetscInfoClassnames);
183:   PetscInfoNumClasses    = n;
184:   PetscInfoInvertClasses = exclude;
185:   /* Process sys class right away */
186:   {
187:     const PetscClassId id = PETSC_SMALLEST_CLASSID;

189:     PetscInfoProcessClass("sys", 1, &id);
190:   }
191:   PetscInfoClassesSet = PETSC_TRUE;
192:   return 0;
193: }

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

198:     Not Collective

200:     Input Parameter:
201: .   classname - Name of the class to search for

203:     Output Parameter:
204: .   found - `PetscBool` indicating whether the classname was found

206:     Note:
207:     Use `PetscObjectGetName()` to retrieve an appropriate classname

209:     Level: developer

211: .seealso: `PetscInfo()`, `PetscInfoSetClasses()`, `PetscInfoSetFromOptions()`, `PetscObjectGetName()`
212: @*/
213: PetscErrorCode PetscInfoGetClass(const char *classname, PetscBool *found)
214: {
215:   PetscInt unused;

219:   PetscEListFind(PetscInfoNumClasses, (const char *const *)PetscInfoClassnames, classname ? classname : "sys", &unused, found);
220:   PetscInfoClassesLocked = PETSC_TRUE;
221:   return 0;
222: }

224: /*@
225:     PetscInfoGetInfo - Returns the current state of several important flags for `PetscInfo()`

227:     Not Collective

229:     Output Parameters:
230: +   infoEnabled - `PETSC_TRUE` if `PetscInfoAllow`(`PETSC_TRUE`) has been called
231: .   classesSet - `PETSC_TRUE` if the list of classes to filter for has been set
232: .   exclude - `PETSC_TRUE` if the class filtering for `PetscInfo()` is inverted
233: .   locked - `PETSC_TRUE` if the list of classes to filter for has been locked
234: -   commSelfFlag - Enum indicating whether `PetscInfo()` will print for communicators of size 1, any size != 1, or all
235:     communicators

237:     Note:
238:     Initially commSelfFlag = `PETSC_INFO_COMM_ALL`

240:     Level: developer

242: .seealso: `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoSetFilterCommSelf`, `PetscInfoSetFromOptions()`
243: @*/
244: PetscErrorCode PetscInfoGetInfo(PetscBool *infoEnabled, PetscBool *classesSet, PetscBool *exclude, PetscBool *locked, PetscInfoCommFlag *commSelfFlag)
245: {
251:   if (infoEnabled) *infoEnabled = PetscLogPrintInfo;
252:   if (classesSet) *classesSet = PetscInfoClassesSet;
253:   if (exclude) *exclude = PetscInfoInvertClasses;
254:   if (locked) *locked = PetscInfoClassesLocked;
255:   if (commSelfFlag) *commSelfFlag = PetscInfoCommFilter;
256:   return 0;
257: }

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

262:     Not Collective

264:     Input Parameters:
265: +   classname - Name of the class to activate/deactivate `PetscInfo()` for
266: .   numClassID - Number of entries in classIDs
267: -   classIDs - Array containing all of the PetscClassids associated with classname

269:     Level: developer

271: .seealso: `PetscInfo()`, `PetscInfoActivateClass()`, `PetscInfoDeactivateClass()`, `PetscInfoSetFromOptions()`
272: @*/
273: PetscErrorCode PetscInfoProcessClass(const char classname[], PetscInt numClassID, const PetscClassId classIDs[])
274: {
275:   PetscBool enabled, exclude, found, opt;
276:   char      logList[256];

279:   PetscAssert(numClassID > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Number of classids %" PetscInt_FMT " <= 0", numClassID);
281:   PetscInfoGetInfo(&enabled, NULL, &exclude, NULL, NULL);
282:   /* -info_exclude is DEPRECATED */
283:   PetscOptionsGetString(NULL, NULL, "-info_exclude", logList, sizeof(logList), &opt);
284:   if (opt) {
285:     PetscBool pkg;

287:     PetscStrInList(classname, logList, ',', &pkg);
288:     if (pkg) {
289:       for (PetscInt i = 0; i < numClassID; ++i) PetscInfoDeactivateClass(classIDs[i]);
290:     }
291:   }
292:   for (PetscInt i = 0; i < numClassID; ++i) {
293:     const PetscClassId idx = classIDs[i] - PETSC_SMALLEST_CLASSID;

295:     PetscFree(PetscInfoNames[idx]);
296:     PetscStrallocpy(classname, PetscInfoNames + idx);
297:   }
298:   PetscInfoGetClass(classname, &found);
299:   if ((found && exclude) || (!found && !exclude)) {
300:     if (PetscInfoNumClasses > 0) {
301:       /* Check if -info was called empty */
302:       for (PetscInt i = 0; i < numClassID; ++i) PetscInfoDeactivateClass(classIDs[i]);
303:     }
304:   } else {
305:     for (PetscInt i = 0; i < numClassID; ++i) PetscInfoActivateClass(classIDs[i]);
306:   }
307:   return 0;
308: }

310: /*@
311:     PetscInfoSetFilterCommSelf - Sets `PetscInfoCommFlag` enum to determine communicator filtering for `PetscInfo()`

313:     Not Collective

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

318:     Level: advanced

320: .seealso: `PetscInfo()`, `PetscInfoGetInfo()`
321: @*/
322: PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag commSelfFlag)
323: {
324:   PetscInfoCommFilter = commSelfFlag;
325:   return 0;
326: }

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

331:     Not Collective

333:     Input Parameter:
334: .   options - Options database, use NULL for default global database

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

339:     Note:
340:     This function is called automatically during `PetscInitialize()` so users usually do not need to call it themselves.

342:     Level: advanced

344: .seealso: `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoSetFile()`, `PetscInfoSetClasses()`, `PetscInfoSetFilterCommSelf()`, `PetscInfoDestroy()`
345: @*/
346: PetscErrorCode PetscInfoSetFromOptions(PetscOptions options)
347: {
348:   char      optstring[PETSC_MAX_PATH_LEN];
349:   PetscBool set;

351:   PetscOptionsDeprecated_Private(NULL, "-info_exclude", NULL, "3.13", "Use -info instead");
352:   PetscOptionsGetString(options, NULL, "-info", optstring, PETSC_STATIC_ARRAY_LENGTH(optstring), &set);
353:   if (set) {
354:     size_t            size_loc0_, size_loc1_, size_loc2_;
355:     char             *loc0_ = NULL, *loc1_ = NULL, *loc2_ = NULL;
356:     char            **loc1_array  = NULL;
357:     PetscBool         loc1_invert = PETSC_FALSE, loc2_invert = PETSC_FALSE;
358:     int               nLoc1_       = 0;
359:     PetscInfoCommFlag commSelfFlag = PETSC_INFO_COMM_ALL;

361:     PetscInfoClassesSet = PETSC_TRUE;
362:     PetscInfoAllow(PETSC_TRUE);
363:     PetscStrallocpy(optstring, &loc0_);
364:     PetscStrchr(loc0_, ':', &loc1_);
365:     if (loc1_) {
366:       *loc1_++ = 0;
367:       if (*loc1_ == '~') {
368:         loc1_invert = PETSC_TRUE;
369:         ++loc1_;
370:       }
371:       PetscStrchr(loc1_, ':', &loc2_);
372:     }
373:     if (loc2_) {
374:       *loc2_++ = 0;
375:       if (*loc2_ == '~') {
376:         loc2_invert = PETSC_TRUE;
377:         ++loc2_;
378:       }
379:     }
380:     PetscStrlen(loc0_, &size_loc0_);
381:     PetscStrlen(loc1_, &size_loc1_);
382:     PetscStrlen(loc2_, &size_loc2_);
383:     if (size_loc1_) {
384:       PetscStrtolower(loc1_);
385:       PetscStrToArray(loc1_, ',', &nLoc1_, &loc1_array);
386:     }
387:     if (size_loc2_) {
388:       PetscBool foundSelf;

390:       PetscStrtolower(loc2_);
391:       PetscStrcmp("self", loc2_, &foundSelf);
392:       if (foundSelf) commSelfFlag = loc2_invert ? PETSC_INFO_COMM_NO_SELF : PETSC_INFO_COMM_ONLY_SELF;
393:     }
394:     PetscInfoSetFile(size_loc0_ ? loc0_ : NULL, "w");
395:     PetscInfoSetClasses(loc1_invert, (PetscInt)nLoc1_, (const char *const *)loc1_array);
396:     PetscInfoSetFilterCommSelf(commSelfFlag);
397:     PetscStrToArrayDestroy(nLoc1_, loc1_array);
398:     PetscFree(loc0_);
399:   }
400:   return 0;
401: }

403: /*@
404:   PetscInfoDestroy - Destroys and resets internal `PetscInfo()` data structures.

406:   Not Collective

408:   Note:
409:   This is automatically called in `PetscFinalize()`. Useful for changing filters mid-program, or culling subsequent
410:   `PetscInfo()` calls down the line.

412:   Level: developer

414: .seealso: `PetscInfo()`, `PetscInfoSetFromOptions()`
415: @*/
416: PetscErrorCode PetscInfoDestroy(void)
417: {
418:   int err;

420:   PetscInfoAllow(PETSC_FALSE);
421:   PetscStrNArrayDestroy(PetscInfoNumClasses, &PetscInfoClassnames);
422:   err = fflush(PetscInfoFile);
424:   if (PetscInfoFilename) PetscFClose(PETSC_COMM_SELF, PetscInfoFile);
425:   PetscFree(PetscInfoFilename);
426:   PetscAssert(PETSC_STATIC_ARRAY_LENGTH(PetscInfoFlags) == PETSC_STATIC_ARRAY_LENGTH(PetscInfoNames), PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscInfoFlags and PetscInfoNames must be the same size");
427:   for (size_t i = 0; i < PETSC_STATIC_ARRAY_LENGTH(PetscInfoFlags); ++i) {
428:     PetscInfoFlags[i] = 1;
429:     PetscFree(PetscInfoNames[i]);
430:   }

432:   PetscInfoClassesLocked = PETSC_FALSE;
433:   PetscInfoInvertClasses = PETSC_FALSE;
434:   PetscInfoClassesSet    = PETSC_FALSE;
435:   PetscInfoNumClasses    = -1;
436:   PetscInfoCommFilter    = PETSC_INFO_COMM_ALL;
437:   return 0;
438: }

440: static PetscErrorCode PetscInfoSetClassActivation_Private(PetscClassId classid, int value)
441: {
442:   if (!classid) classid = PETSC_SMALLEST_CLASSID;
443:   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = value;
444:   return 0;
445: }

447: /*@
448:   PetscInfoDeactivateClass - Deactivates `PetscInfo()` messages for a PETSc object class.

450:   Not Collective

452:   Input Parameter:
453: . classid - The object class,  e.g., `MAT_CLASSID`, `SNES_CLASSID`, etc.

455:   Note:
456:   One can pass 0 to deactivate all messages that are not associated with an object.

458:   Level: developer

460: .seealso: `PetscInfoActivateClass()`, `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoSetFromOptions()`
461: @*/
462: PetscErrorCode PetscInfoDeactivateClass(PetscClassId classid)
463: {
464:   PetscInfoSetClassActivation_Private(classid, 0);
465:   return 0;
466: }

468: /*@
469:   PetscInfoActivateClass - Activates `PetscInfo()` messages for a PETSc object class.

471:   Not Collective

473:   Input Parameter:
474: . classid - The object class, e.g., `MAT_CLASSID`, `SNES_CLASSID`, etc.

476:   Note:
477:   One can pass 0 to activate all messages that are not associated with an object.

479:   Level: developer

481: .seealso: `PetscInfoDeactivateClass()`, `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoSetFromOptions()`
482: @*/
483: PetscErrorCode PetscInfoActivateClass(PetscClassId classid)
484: {
485:   PetscInfoSetClassActivation_Private(classid, 1);
486:   return 0;
487: }

489: /*
490:    If the option -history was used, then all printed PetscInfo()
491:   messages are also printed to the history file, called by default
492:   .petschistory in ones home directory.
493: */
494: PETSC_INTERN FILE *petsc_history;

496: /*MC
497:     PetscInfo - Logs informative data

499:    Synopsis:
500: #include <petscsys.h>
501:        PetscErrorCode PetscInfo(PetscObject obj, const char message[])
502:        PetscErrorCode PetscInfo(PetscObject obj, const char formatmessage[],arg1)
503:        PetscErrorCode PetscInfo(PetscObject obj, const char formatmessage[],arg1,arg2)
504:        ...

506:     Collective

508:     Input Parameters:
509: +   obj - object most closely associated with the logging statement or `NULL`
510: .   message - logging message
511: .   formatmessage - logging message using standard "printf" format
512: -   arg1, arg2, ... - arguments of the format

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

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

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

522:     No filename means standard output `PETSC_STDOUT` is used.

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

529:     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.
530:     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.

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

534:     Example of Usage:
535: $     Mat A;
536: $     PetscInt alpha;
537: $     ...
538: $     PetscInfo(A,"Matrix uses parameter alpha=%" PetscInt_FMT "\n",alpha);

540:     Options Examples:
541:     Each call of the form
542: $     PetscInfo(obj, msg);
543: $     PetscInfo(obj, msg, arg1);
544: $     PetscInfo(obj, msg, arg1, arg2);
545:     is evaluated as follows.
546: $     -info or -info :: prints msg to PETSC_STDOUT, for any obj regardless class or communicator
547: $     -info :mat:self prints msg to PETSC_STDOUT only if class of obj is Mat, and its communicator has size = 1
548: $     -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
549: $     -info :sys prints to PETSC_STDOUT only if obj is NULL
550:     Note that
551: $     -info :sys:~self
552:     deactivates all info messages because sys means obj = NULL which implies PETSC_COMM_SELF but ~self filters out everything on PETSC_COMM_SELF.

554:     Fortran Note:
555:     This function does not take the obj argument, there is only the `PetscInfo()`
556:      version, not `PetscInfo()` etc.

558:     Level: intermediate

560: .seealso: `PetscInfoAllow()`, `PetscInfoSetFromOptions()`
561: M*/
562: PetscErrorCode PetscInfo_Private(const char func[], PetscObject obj, const char message[], ...)
563: {
564:   PetscClassId classid = PETSC_SMALLEST_CLASSID;
565:   PetscBool    enabled = PETSC_FALSE;
566:   MPI_Comm     comm    = PETSC_COMM_SELF;
567:   PetscMPIInt  rank;

569:   if (obj) {
571:     classid = obj->classid;
572:   }
574:   PetscInfoEnabled(classid, &enabled);
575:   if (!enabled) return 0;
576:   if (obj) PetscObjectGetComm(obj, &comm);
577:   MPI_Comm_rank(comm, &rank);
578:   /* rank > 0 always jumps out */
579:   if (rank) return 0;
580:   else {
581:     PetscMPIInt size;

583:     MPI_Comm_size(comm, &size);
584:     /* If no self printing is allowed, and size too small, get out */
585:     if ((PetscInfoCommFilter == PETSC_INFO_COMM_NO_SELF) && (size < 2)) return 0;
586:     /* If ONLY self printing, and size too big, get out */
587:     if ((PetscInfoCommFilter == PETSC_INFO_COMM_ONLY_SELF) && (size > 1)) return 0;
588:   }
589:   /* Mute info messages within this function */
590:   {
591:     const PetscBool oldflag = PetscLogPrintInfo;
592:     va_list         Argp;
593:     PetscMPIInt     urank;
594:     int             err;
595:     char            string[8 * 1024];
596:     size_t          fullLength, len;

598:     PetscLogPrintInfo = PETSC_FALSE;
599:     MPI_Comm_rank(MPI_COMM_WORLD, &urank);
600:     va_start(Argp, message);
601:     PetscSNPrintf(string, PETSC_STATIC_ARRAY_LENGTH(string), "[%d] <%s> %s(): ", urank, PetscInfoNames[classid - PETSC_SMALLEST_CLASSID], func);
602:     PetscStrlen(string, &len);
603:     PetscVSNPrintf(string + len, 8 * 1024 - len, message, &fullLength, Argp);
604:     PetscFPrintf(PETSC_COMM_SELF, PetscInfoFile, "%s", string);
605:     err = fflush(PetscInfoFile);
607:     if (petsc_history) {
608:       va_start(Argp, message);
609:       (*PetscVFPrintf)(petsc_history, message, Argp);
610:     }
611:     va_end(Argp);
612:     PetscLogPrintInfo = oldflag;
613:   }
614:   return 0;
615: }