xref: /petsc/src/sys/info/verboseinfo.c (revision ffa8c5705e8ab2cf85ee1d14dbe507a6e2eb5283)
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>        /*I    "petscsys.h"   I*/
6 
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.
10 
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.
15 
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,
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;
36 FILE                      *PetscInfoFile = NULL;
37 
38 /*@
39     PetscInfoEnabled - Checks whether a given OBJECT_CLASSID is allowed to print using PetscInfo()
40 
41     Not Collective
42 
43     Input Parameters:
44 .   classid - PetscClassid retrieved from a PetscObject e.g. VEC_CLASSID
45 
46     Output Parameter:
47 .   enabled - PetscBool indicating whether this classid is allowed to print
48 
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.
52 
53     Level: advanced
54 
55 .seealso: PetscInfo(), PetscInfoAllow(), PetscInfoGetInfo(), PetscObjectGetClassid()
56 @*/
57 PetscErrorCode PetscInfoEnabled(PetscClassId classid, PetscBool *enabled)
58 {
59   PetscFunctionBegin;
60   PetscCheckFalse(classid < PETSC_SMALLEST_CLASSID,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Classid (current: %d) must be equal to or greater than PETSC_SMALLEST_CLASSID", classid);
61   *enabled = (PetscBool) (PetscLogPrintInfo && PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID]);
62   PetscFunctionReturn(0);
63 }
64 
65 /*@
66     PetscInfoAllow - Enables/disables PetscInfo() messages
67 
68     Not Collective
69 
70     Input Parameter:
71 .   flag - PETSC_TRUE or PETSC_FALSE
72 
73     Level: advanced
74 
75 .seealso: PetscInfo(), PetscInfoEnabled(), PetscInfoGetInfo(), PetscInfoSetFromOptions()
76 @*/
77 PetscErrorCode PetscInfoAllow(PetscBool flag)
78 {
79   PetscFunctionBegin;
80   PetscLogPrintInfo = flag;
81   PetscFunctionReturn(0);
82 }
83 
84 /*@C
85     PetscInfoSetFile - Sets the printing destination for all PetscInfo() calls
86 
87     Not Collective
88 
89     Input Parameters:
90 +   filename - Name of the file where PetscInfo() will print to
91 -   mode - Write mode passed to PetscFOpen()
92 
93     Notes:
94     Use filename=NULL to set PetscInfo() to write to PETSC_STDOUT.
95 
96     Level: advanced
97 
98 .seealso: PetscInfo(), PetscInfoSetFile(), PetscInfoSetFromOptions(), PetscFOpen()
99 @*/
100 PetscErrorCode PetscInfoSetFile(const char filename[], const char mode[])
101 {
102   char            fname[PETSC_MAX_PATH_LEN], tname[11];
103   PetscMPIInt     rank;
104 
105   PetscFunctionBegin;
106   if (!PetscInfoFile) PetscInfoFile = PETSC_STDOUT;
107   PetscCall(PetscFree(PetscInfoFilename));
108   if (filename) {
109     PetscBool  oldflag;
110     PetscValidCharPointer(filename, 1);
111     PetscCall(PetscFixFilename(filename, fname));
112     PetscCall(PetscStrallocpy(fname, &PetscInfoFilename));
113     PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
114     sprintf(tname, ".%d", rank);
115     PetscCall(PetscStrcat(fname, tname));
116     oldflag = PetscLogPrintInfo; PetscLogPrintInfo = PETSC_FALSE;
117     PetscCall(PetscFOpen(MPI_COMM_SELF, fname, mode, &PetscInfoFile));
118     PetscLogPrintInfo = oldflag;
119     /* PetscFOpen will write to PETSC_STDOUT and not PetscInfoFile here, so we disable the PetscInfo call inside it, and
120      call it afterwards so that it actually writes to file */
121     PetscCall(PetscInfo(NULL, "Opened PetscInfo file %s\n", fname));
122   }
123   PetscFunctionReturn(0);
124 }
125 
126 /*@C
127     PetscInfoGetFile - Gets the name and FILE pointer of the file where PetscInfo() prints to
128 
129     Not Collective
130 
131     Output Parameters:
132 +   filename - The name of the output file
133 -   InfoFile - The FILE pointer for the output file
134 
135     Level: advanced
136 
137     Note:
138     This routine allocates and copies the filename so that the filename survives PetscInfoDestroy(). The user is
139     therefore responsible for freeing the allocated filename pointer afterwards.
140 
141     Fortran Note:
142     This routine is not supported in Fortran.
143 
144 .seealso: PetscInfo(), PetscInfoSetFile(), PetscInfoSetFromOptions(), PetscInfoDestroy()
145 @*/
146 PetscErrorCode PetscInfoGetFile(char **filename, FILE **InfoFile)
147 {
148   PetscFunctionBegin;
149   PetscValidPointer(filename, 1);
150   PetscValidPointer(InfoFile, 2);
151   PetscCall(PetscStrallocpy(PetscInfoFilename, filename));
152   *InfoFile = PetscInfoFile;
153   PetscFunctionReturn(0);
154 }
155 
156 /*@C
157     PetscInfoSetClasses - Sets the classes which PetscInfo() is filtered for/against
158 
159     Not Collective
160 
161     Input Parameters:
162 +   exclude - Whether or not to invert the filter, i.e. if exclude is true, PetscInfo() will print from every class that
163     is NOT one of the classes specified
164 .   N - Number of classes to filter for (size of classnames)
165 -   classnames - String array containing the names of classes to filter for, e.g. "vec"
166 
167     Notes:
168     Not for use in Fortran
169 
170     This function CANNOT be called after PetscInfoGetClass() or PetscInfoProcessClass() has been called.
171 
172     Names in the classnames list should correspond to the names returned by PetscObjectGetClassName().
173 
174     This function only sets the list of class names.
175     The actual filtering is deferred to PetscInfoProcessClass(), except of sys which is processed right away.
176     The reason for this is that we need to set the list of included/excluded classes before their classids are known.
177     Typically the classid is assigned and PetscInfoProcessClass() called in <Class>InitializePackage() (e.g. VecInitializePackage()).
178 
179     Level: developer
180 
181 .seealso: PetscInfo(), PetscInfoGetClass(), PetscInfoProcessClass(), PetscInfoSetFromOptions(), PetscStrToArray(), PetscObjectGetName()
182 @*/
183 PetscErrorCode PetscInfoSetClasses(PetscBool exclude, PetscInt N, const char *const *classnames)
184 {
185   PetscFunctionBegin;
186   PetscCheck(!PetscInfoClassesLocked,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscInfoSetClasses() cannot be called after PetscInfoGetClass() or PetscInfoProcessClass()");
187   PetscCall(PetscStrNArrayDestroy(PetscInfoNumClasses, &PetscInfoClassnames));
188   PetscCall(PetscStrNArrayallocpy(N, classnames, &PetscInfoClassnames));
189   PetscInfoNumClasses = N;
190   PetscInfoInvertClasses = exclude;
191   {
192     /* Process sys class right away */
193     PetscClassId  sysclassid = PETSC_SMALLEST_CLASSID;
194     PetscCall(PetscInfoProcessClass("sys", 1, &sysclassid));
195   }
196   PetscInfoClassesSet = PETSC_TRUE;
197   PetscFunctionReturn(0);
198 }
199 
200 /*@C
201     PetscInfoGetClass - Indicates whether the provided classname is marked as a filter in PetscInfo() as set by PetscInfoSetClasses()
202 
203     Not Collective
204 
205     Input Parameter:
206 .   classname - Name of the class to search for
207 
208     Output Parameter:
209 .   found - PetscBool indicating whether the classname was found
210 
211     Notes:
212     Use PetscObjectGetName() to retrieve an appropriate classname
213 
214     Level: developer
215 
216 .seealso: PetscInfo(), PetscInfoSetClasses(), PetscInfoSetFromOptions(), PetscObjectGetName()
217 @*/
218 PetscErrorCode PetscInfoGetClass(const char *classname, PetscBool *found)
219 {
220   PetscInt        idx;
221 
222   PetscFunctionBegin;
223   PetscValidCharPointer(classname,1);
224   PetscCall(PetscEListFind(PetscInfoNumClasses, (const char *const *) PetscInfoClassnames, classname ? classname : "sys", &idx, found));
225   PetscInfoClassesLocked = PETSC_TRUE;
226   PetscFunctionReturn(0);
227 }
228 
229 /*@
230     PetscInfoGetInfo - Returns the current state of several important flags for PetscInfo()
231 
232     Not Collective
233 
234     Output Parameters:
235 +   infoEnabled - PETSC_TRUE if PetscInfoAllow(PETSC_TRUE) has been called
236 .   classesSet - PETSC_TRUE if the list of classes to filter for has been set
237 .   exclude - PETSC_TRUE if the class filtering for PetscInfo() is inverted
238 .   locked - PETSC_TRUE if the list of classes to filter for has been locked
239 -   commSelfFlag - Enum indicating whether PetscInfo() will print for communicators of size 1, any size != 1, or all
240     communicators
241 
242     Notes:
243     Initially commSelfFlag = PETSC_INFO_COMM_ALL
244 
245     Level: developer
246 
247 .seealso: PetscInfo(), PetscInfoAllow(), PetscInfoSetFilterCommSelf, PetscInfoSetFromOptions()
248 @*/
249 PetscErrorCode PetscInfoGetInfo(PetscBool *infoEnabled, PetscBool *classesSet, PetscBool *exclude, PetscBool *locked, PetscInfoCommFlag *commSelfFlag)
250 {
251   PetscFunctionBegin;
252   if (infoEnabled)  *infoEnabled  = PetscLogPrintInfo;
253   if (classesSet)   *classesSet   = PetscInfoClassesSet;
254   if (exclude)      *exclude      = PetscInfoInvertClasses;
255   if (locked)       *locked       = PetscInfoClassesLocked;
256   if (commSelfFlag) *commSelfFlag = PetscInfoCommFilter;
257   PetscFunctionReturn(0);
258 }
259 
260 /*@C
261     PetscInfoProcessClass - Activates or deactivates a class based on the filtering status of PetscInfo()
262 
263     Not Collective
264 
265     Input Parameters:
266 +   classname - Name of the class to activate/deactivate PetscInfo() for
267 .   numClassID - Number of entries in classIDs
268 -   classIDs - Array containing all of the PetscClassids associated with classname
269 
270     Level: developer
271 
272 .seealso: PetscInfo(), PetscInfoActivateClass(), PetscInfoDeactivateClass(), PetscInfoSetFromOptions()
273 @*/
274 PetscErrorCode PetscInfoProcessClass(const char classname[], PetscInt numClassID, PetscClassId classIDs[])
275 {
276   PetscInt        i;
277   PetscBool       enabled, exclude, found, opt, pkg;
278   char            logList[256];
279 
280   PetscFunctionBegin;
281   PetscValidCharPointer(classname, 1);
282   PetscCall(PetscInfoGetInfo(&enabled, NULL, &exclude, NULL, NULL));
283   /* -info_exclude is DEPRECATED */
284   PetscCall(PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt));
285   if (opt) {
286     PetscCall(PetscStrInList(classname,logList,',',&pkg));
287     if (pkg) {
288       for (i = 0; i < numClassID; ++i) {
289         PetscCall(PetscInfoDeactivateClass(classIDs[i]));
290       }
291     }
292   }
293   PetscCall(PetscInfoGetClass(classname, &found));
294   if ((found && exclude) || (!found && !exclude)) {
295     if (PetscInfoNumClasses > 0) {
296       /* Check if -info was called empty */
297       for (i = 0; i < numClassID; ++i) {
298         PetscCall(PetscInfoDeactivateClass(classIDs[i]));
299       }
300     }
301   } else {
302     for (i = 0; i < numClassID; ++i) {
303       PetscCall(PetscInfoActivateClass(classIDs[i]));
304     }
305   }
306   PetscFunctionReturn(0);
307 }
308 
309 /*@
310     PetscInfoSetFilterCommSelf - Sets PetscInfoCommFlag enum to determine communicator filtering for PetscInfo()
311 
312     Not Collective
313 
314     Input Parameter:
315 .   commSelfFlag - Enum value indicating method with which to filter PetscInfo() based on the size of the communicator of the object calling PetscInfo()
316 
317     Level: advanced
318 
319 .seealso: PetscInfo(), PetscInfoGetInfo()
320 @*/
321 PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag commSelfFlag)
322 {
323   PetscFunctionBegin;
324   PetscInfoCommFilter = commSelfFlag;
325   PetscFunctionReturn(0);
326 }
327 
328 /*@
329     PetscInfoSetFromOptions - Configure PetscInfo() using command line options, enabling or disabling various calls to PetscInfo()
330 
331     Not Collective
332 
333     Input Parameter:
334 .   options - Options database, use NULL for default global database
335 
336     Options Database Keys:
337 .   -info [filename][:[~]<list,of,classnames>[:[~]self]] - specify which informative messages are printed, See PetscInfo().
338 
339     Notes:
340     This function is called automatically during PetscInitialize() so users usually do not need to call it themselves.
341 
342     Level: advanced
343 
344 .seealso: PetscInfo(), PetscInfoAllow(), PetscInfoSetFile(), PetscInfoSetClasses(), PetscInfoSetFilterCommSelf(), PetscInfoDestroy()
345 @*/
346 PetscErrorCode PetscInfoSetFromOptions(PetscOptions options)
347 {
348   char               optstring[PETSC_MAX_PATH_LEN], *loc0_ = NULL, *loc1_ = NULL, *loc2_ = NULL;
349   char               **loc1_array = NULL;
350   PetscBool          set, loc1_invert = PETSC_FALSE, loc2_invert = PETSC_FALSE, foundSelf = PETSC_FALSE;
351   size_t             size_loc0_ = 0, size_loc1_ = 0, size_loc2_ = 0;
352   int                nLoc1_ = 0;
353   PetscInfoCommFlag  commSelfFlag = PETSC_INFO_COMM_ALL;
354 
355   PetscFunctionBegin;
356   PetscCall(PetscOptionsDeprecated_Private(NULL,"-info_exclude", NULL, "3.13", "Use -info instead"));
357   PetscCall(PetscOptionsGetString(options, NULL, "-info", optstring, sizeof(optstring), &set));
358   if (set) {
359     PetscInfoClassesSet = PETSC_TRUE;
360     PetscCall(PetscInfoAllow(PETSC_TRUE));
361     PetscCall(PetscStrallocpy(optstring,&loc0_));
362     PetscCall(PetscStrchr(loc0_,':',&loc1_));
363     if (loc1_) {
364       *loc1_++ = 0;
365       if (*loc1_ == '~') {
366         loc1_invert = PETSC_TRUE;
367         ++loc1_;
368       }
369       PetscCall(PetscStrchr(loc1_,':',&loc2_));
370     }
371     if (loc2_) {
372       *loc2_++ = 0;
373       if (*loc2_ == '~') {
374         loc2_invert = PETSC_TRUE;
375         ++loc2_;
376       }
377     }
378     PetscCall(PetscStrlen(loc0_, &size_loc0_));
379     PetscCall(PetscStrlen(loc1_, &size_loc1_));
380     PetscCall(PetscStrlen(loc2_, &size_loc2_));
381     if (size_loc1_) {
382       PetscCall(PetscStrtolower(loc1_));
383       PetscCall(PetscStrToArray(loc1_, ',', &nLoc1_, &loc1_array));
384     }
385     if (size_loc2_) {
386       PetscCall(PetscStrtolower(loc2_));
387       PetscCall(PetscStrcmp("self", loc2_, &foundSelf));
388       if (foundSelf) {
389         if (loc2_invert) {
390           commSelfFlag = PETSC_INFO_COMM_NO_SELF;
391         } else {
392           commSelfFlag = PETSC_INFO_COMM_ONLY_SELF;
393         }
394       }
395     }
396     PetscCall(PetscInfoSetFile(size_loc0_ ? loc0_ : NULL, "w"));
397     PetscCall(PetscInfoSetClasses(loc1_invert, (PetscInt) nLoc1_, (const char *const *) loc1_array));
398     PetscCall(PetscInfoSetFilterCommSelf(commSelfFlag));
399     PetscCall(PetscStrToArrayDestroy(nLoc1_, loc1_array));
400     PetscCall(PetscFree(loc0_));
401   }
402   PetscFunctionReturn(0);
403 }
404 
405 /*@
406   PetscInfoDestroy - Destroys and resets internal PetscInfo() data structures.
407 
408   Not Collective
409 
410   Notes:
411   This is automatically called in PetscFinalize(). Useful for changing filters mid-program, or culling subsequent
412   PetscInfo() calls down the line.
413 
414   Level: developer
415 
416 .seealso: PetscInfo(), PetscInfoSetFromOptions()
417 @*/
418 PetscErrorCode PetscInfoDestroy(void)
419 {
420   int             err;
421   size_t          i;
422 
423   PetscFunctionBegin;
424   PetscCall(PetscInfoAllow(PETSC_FALSE));
425   PetscCall(PetscStrNArrayDestroy(PetscInfoNumClasses, &PetscInfoClassnames));
426   err  = fflush(PetscInfoFile);
427   PetscCheck(!err,PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
428   if (PetscInfoFilename) {
429     PetscCall(PetscFClose(MPI_COMM_SELF, PetscInfoFile));
430   }
431   PetscCall(PetscFree(PetscInfoFilename));
432   for (i=0; i<sizeof(PetscInfoFlags)/sizeof(PetscInfoFlags[0]); i++) PetscInfoFlags[i] = 1;
433   PetscInfoClassesLocked = PETSC_FALSE;
434   PetscInfoInvertClasses = PETSC_FALSE;
435   PetscInfoClassesSet = PETSC_FALSE;
436   PetscInfoNumClasses = -1;
437   PetscInfoCommFilter = PETSC_INFO_COMM_ALL;
438   PetscFunctionReturn(0);
439 }
440 
441 /*@
442   PetscInfoDeactivateClass - Deactivates PetscInfo() messages for a PETSc object class.
443 
444   Not Collective
445 
446   Input Parameter:
447 . classid - The object class,  e.g., MAT_CLASSID, SNES_CLASSID, etc.
448 
449   Notes:
450   One can pass 0 to deactivate all messages that are not associated with an object.
451 
452   Level: developer
453 
454 .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow(), PetscInfoSetFromOptions()
455 @*/
456 PetscErrorCode  PetscInfoDeactivateClass(PetscClassId classid)
457 {
458   PetscFunctionBegin;
459   if (!classid) classid = PETSC_SMALLEST_CLASSID;
460   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 0;
461   PetscFunctionReturn(0);
462 }
463 
464 /*@
465   PetscInfoActivateClass - Activates PetscInfo() messages for a PETSc object class.
466 
467   Not Collective
468 
469   Input Parameter:
470 . classid - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc.
471 
472   Notes:
473   One can pass 0 to activate all messages that are not associated with an object.
474 
475   Level: developer
476 
477 .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow(), PetscInfoSetFromOptions()
478 @*/
479 PetscErrorCode  PetscInfoActivateClass(PetscClassId classid)
480 {
481   PetscFunctionBegin;
482   if (!classid) classid = PETSC_SMALLEST_CLASSID;
483   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 1;
484   PetscFunctionReturn(0);
485 }
486 
487 /*
488    If the option -history was used, then all printed PetscInfo()
489   messages are also printed to the history file, called by default
490   .petschistory in ones home directory.
491 */
492 PETSC_INTERN FILE *petsc_history;
493 
494 /*MC
495     PetscInfo - Logs informative data
496 
497    Synopsis:
498        #include <petscsys.h>
499        PetscErrorCode PetscInfo(PetscObject obj, const char message[])
500        PetscErrorCode PetscInfo(PetscObject obj, const char formatmessage[],arg1)
501        PetscErrorCode PetscInfo(PetscObject obj, const char formatmessage[],arg1,arg2)
502        ...
503 
504     Collective on obj
505 
506     Input Parameters:
507 +   obj - object most closely associated with the logging statement or NULL
508 .   message - logging message
509 .   formatmessage - logging message using standard "printf" format
510 -   arg1, arg2, ... - arguments of the format
511 
512     Notes:
513     PetscInfo() prints only from the first processor in the communicator of obj.
514     If obj is NULL, the PETSC_COMM_SELF communicator is used, i.e. every rank of PETSC_COMM_WORLD prints the message.
515 
516     Extent of the printed messages can be controlled using the option database key -info as follows.
517 
518 $   -info [filename][:[~]<list,of,classnames>[:[~]self]]
519 
520     No filename means standard output PETSC_STDOUT is used.
521 
522     The optional <list,of,classnames> is a comma separated list of enabled classes, e.g. vec,mat,ksp.
523     If this list is not specified, all classes are enabled.
524     Prepending the list with ~ means inverted selection, i.e. all classes except the listed are enabled.
525     A special classname sys relates to PetscInfo() with obj being NULL.
526 
527     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.
528     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.
529 
530     All classname/self matching is case insensitive. Filename is case sensitive.
531 
532     Example of Usage:
533 $     Mat A;
534 $     PetscInt alpha;
535 $     ...
536 $     PetscInfo(A,"Matrix uses parameter alpha=%" PetscInt_FMT "\n",alpha);
537 
538     Options Examples:
539     Each call of the form
540 $     PetscInfo(obj, msg);
541 $     PetscInfo(obj, msg, arg1);
542 $     PetscInfo(obj, msg, arg1, arg2);
543     is evaluated as follows.
544 $     -info or -info :: prints msg to PETSC_STDOUT, for any obj regardless class or communicator
545 $     -info :mat:self prints msg to PETSC_STDOUT only if class of obj is Mat, and its communicator has size = 1
546 $     -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
547 $     -info :sys prints to PETSC_STDOUT only if obj is NULL
548     Note that
549 $     -info :sys:~self
550     deactivates all info messages because sys means obj = NULL which implies PETSC_COMM_SELF but ~self filters out everything on PETSC_COMM_SELF.
551 
552     Fortran Note:
553     This function does not take the obj argument, there is only the PetscInfo()
554      version, not PetscInfo() etc.
555 
556     Level: intermediate
557 
558 .seealso: PetscInfoAllow(), PetscInfoSetFromOptions()
559 M*/
560 PetscErrorCode  PetscInfo_Private(const char func[],PetscObject obj, const char message[], ...)
561 {
562   va_list        Argp;
563   PetscMPIInt    rank = 0,urank,size = 1;
564   PetscClassId   classid;
565   PetscBool      enabled = PETSC_FALSE, oldflag;
566   char           string[8*1024];
567   size_t         fullLength,len;
568   int            err;
569 
570   PetscFunctionBegin;
571   if (obj) PetscValidHeader(obj,2);
572   classid = obj ? obj->classid : PETSC_SMALLEST_CLASSID;
573   PetscCall(PetscInfoEnabled(classid, &enabled));
574   if (!enabled) PetscFunctionReturn(0);
575   PetscValidCharPointer(message,3);
576   if (obj) {
577     PetscCallMPI(MPI_Comm_rank(obj->comm, &rank));
578     PetscCallMPI(MPI_Comm_size(obj->comm, &size));
579   }
580   /* rank > 0 always jumps out */
581   if (rank) PetscFunctionReturn(0);
582   if (!PetscInfoCommFilter && (size < 2)) {
583     /* If no self printing is allowed, and size too small get out */
584     PetscFunctionReturn(0);
585   } else if ((PetscInfoCommFilter == PETSC_INFO_COMM_ONLY_SELF) && (size > 1)) {
586     /* If ONLY self printing, and size too big, get out */
587     PetscFunctionReturn(0);
588   }
589   /* Mute info messages within this function */
590   oldflag = PetscLogPrintInfo; PetscLogPrintInfo = PETSC_FALSE;
591   PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &urank));
592   va_start(Argp, message);
593   sprintf(string, "[%d] %s(): ",urank,func);
594   PetscCall(PetscStrlen(string, &len));
595   PetscCall(PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp));
596   PetscCall(PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string));
597   err  = fflush(PetscInfoFile);
598   PetscCheck(!err,PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
599   if (petsc_history) {
600     va_start(Argp, message);
601     PetscCall((*PetscVFPrintf)(petsc_history, message, Argp));
602   }
603   va_end(Argp);
604   PetscLogPrintInfo = oldflag;
605   PetscFunctionReturn(0);
606 }
607