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 PetscCheck(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) PetscCall(PetscFClose(MPI_COMM_SELF, PetscInfoFile)); 429 PetscCall(PetscFree(PetscInfoFilename)); 430 for (i=0; i<PETSC_STATIC_ARRAY_LENGTH(PetscInfoFlags); i++) PetscInfoFlags[i] = 1; 431 PetscInfoClassesLocked = PETSC_FALSE; 432 PetscInfoInvertClasses = PETSC_FALSE; 433 PetscInfoClassesSet = PETSC_FALSE; 434 PetscInfoNumClasses = -1; 435 PetscInfoCommFilter = PETSC_INFO_COMM_ALL; 436 PetscFunctionReturn(0); 437 } 438 439 /*@ 440 PetscInfoDeactivateClass - Deactivates PetscInfo() messages for a PETSc object class. 441 442 Not Collective 443 444 Input Parameter: 445 . classid - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc. 446 447 Notes: 448 One can pass 0 to deactivate all messages that are not associated with an object. 449 450 Level: developer 451 452 .seealso: `PetscInfoActivateClass()`, `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoSetFromOptions()` 453 @*/ 454 PetscErrorCode PetscInfoDeactivateClass(PetscClassId classid) 455 { 456 PetscFunctionBegin; 457 if (!classid) classid = PETSC_SMALLEST_CLASSID; 458 PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 0; 459 PetscFunctionReturn(0); 460 } 461 462 /*@ 463 PetscInfoActivateClass - Activates PetscInfo() messages for a PETSc object class. 464 465 Not Collective 466 467 Input Parameter: 468 . classid - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc. 469 470 Notes: 471 One can pass 0 to activate all messages that are not associated with an object. 472 473 Level: developer 474 475 .seealso: `PetscInfoDeactivateClass()`, `PetscInfo()`, `PetscInfoAllow()`, `PetscInfoSetFromOptions()` 476 @*/ 477 PetscErrorCode PetscInfoActivateClass(PetscClassId classid) 478 { 479 PetscFunctionBegin; 480 if (!classid) classid = PETSC_SMALLEST_CLASSID; 481 PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 1; 482 PetscFunctionReturn(0); 483 } 484 485 /* 486 If the option -history was used, then all printed PetscInfo() 487 messages are also printed to the history file, called by default 488 .petschistory in ones home directory. 489 */ 490 PETSC_INTERN FILE *petsc_history; 491 492 /*MC 493 PetscInfo - Logs informative data 494 495 Synopsis: 496 #include <petscsys.h> 497 PetscErrorCode PetscInfo(PetscObject obj, const char message[]) 498 PetscErrorCode PetscInfo(PetscObject obj, const char formatmessage[],arg1) 499 PetscErrorCode PetscInfo(PetscObject obj, const char formatmessage[],arg1,arg2) 500 ... 501 502 Collective on obj 503 504 Input Parameters: 505 + obj - object most closely associated with the logging statement or NULL 506 . message - logging message 507 . formatmessage - logging message using standard "printf" format 508 - arg1, arg2, ... - arguments of the format 509 510 Notes: 511 PetscInfo() prints only from the first processor in the communicator of obj. 512 If obj is NULL, the PETSC_COMM_SELF communicator is used, i.e. every rank of PETSC_COMM_WORLD prints the message. 513 514 Extent of the printed messages can be controlled using the option database key -info as follows. 515 516 $ -info [filename][:[~]<list,of,classnames>[:[~]self]] 517 518 No filename means standard output PETSC_STDOUT is used. 519 520 The optional <list,of,classnames> is a comma separated list of enabled classes, e.g. vec,mat,ksp. 521 If this list is not specified, all classes are enabled. 522 Prepending the list with ~ means inverted selection, i.e. all classes except the listed are enabled. 523 A special classname sys relates to PetscInfo() with obj being NULL. 524 525 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. 526 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. 527 528 All classname/self matching is case insensitive. Filename is case sensitive. 529 530 Example of Usage: 531 $ Mat A; 532 $ PetscInt alpha; 533 $ ... 534 $ PetscInfo(A,"Matrix uses parameter alpha=%" PetscInt_FMT "\n",alpha); 535 536 Options Examples: 537 Each call of the form 538 $ PetscInfo(obj, msg); 539 $ PetscInfo(obj, msg, arg1); 540 $ PetscInfo(obj, msg, arg1, arg2); 541 is evaluated as follows. 542 $ -info or -info :: prints msg to PETSC_STDOUT, for any obj regardless class or communicator 543 $ -info :mat:self prints msg to PETSC_STDOUT only if class of obj is Mat, and its communicator has size = 1 544 $ -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 545 $ -info :sys prints to PETSC_STDOUT only if obj is NULL 546 Note that 547 $ -info :sys:~self 548 deactivates all info messages because sys means obj = NULL which implies PETSC_COMM_SELF but ~self filters out everything on PETSC_COMM_SELF. 549 550 Fortran Note: 551 This function does not take the obj argument, there is only the PetscInfo() 552 version, not PetscInfo() etc. 553 554 Level: intermediate 555 556 .seealso: `PetscInfoAllow()`, `PetscInfoSetFromOptions()` 557 M*/ 558 PetscErrorCode PetscInfo_Private(const char func[],PetscObject obj, const char message[], ...) 559 { 560 va_list Argp; 561 PetscMPIInt rank = 0,urank,size = 1; 562 PetscClassId classid; 563 PetscBool enabled = PETSC_FALSE, oldflag; 564 char string[8*1024]; 565 size_t fullLength,len; 566 int err; 567 568 PetscFunctionBegin; 569 if (obj) PetscValidHeader(obj,2); 570 classid = obj ? obj->classid : PETSC_SMALLEST_CLASSID; 571 PetscCall(PetscInfoEnabled(classid, &enabled)); 572 if (!enabled) PetscFunctionReturn(0); 573 PetscValidCharPointer(message,3); 574 if (obj) { 575 PetscCallMPI(MPI_Comm_rank(obj->comm, &rank)); 576 PetscCallMPI(MPI_Comm_size(obj->comm, &size)); 577 } 578 /* rank > 0 always jumps out */ 579 if (rank) PetscFunctionReturn(0); 580 if (!PetscInfoCommFilter && (size < 2)) { 581 /* If no self printing is allowed, and size too small get out */ 582 PetscFunctionReturn(0); 583 } else if ((PetscInfoCommFilter == PETSC_INFO_COMM_ONLY_SELF) && (size > 1)) { 584 /* If ONLY self printing, and size too big, get out */ 585 PetscFunctionReturn(0); 586 } 587 /* Mute info messages within this function */ 588 oldflag = PetscLogPrintInfo; PetscLogPrintInfo = PETSC_FALSE; 589 PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &urank)); 590 va_start(Argp, message); 591 sprintf(string, "[%d] %s(): ",urank,func); 592 PetscCall(PetscStrlen(string, &len)); 593 PetscCall(PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp)); 594 PetscCall(PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string)); 595 err = fflush(PetscInfoFile); 596 PetscCheck(!err,PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 597 if (petsc_history) { 598 va_start(Argp, message); 599 PetscCall((*PetscVFPrintf)(petsc_history, message, Argp)); 600 } 601 va_end(Argp); 602 PetscLogPrintInfo = oldflag; 603 PetscFunctionReturn(0); 604 } 605