15c6c1daeSBarry Smith 25c6c1daeSBarry Smith /* 35c6c1daeSBarry Smith PetscInfo() is contained in a different file from the other profiling to 45c6c1daeSBarry Smith allow it to be replaced at link time by an alternative routine. 55c6c1daeSBarry Smith */ 6afcb2eb5SJed Brown #include <petsc-private/petscimpl.h> /*I "petscsys.h" I*/ 75c6c1daeSBarry Smith 85c6c1daeSBarry Smith /* 95c6c1daeSBarry Smith The next three variables determine which, if any, PetscInfo() calls are used. 105c6c1daeSBarry Smith If PetscLogPrintInfo is zero, no info messages are printed. 115c6c1daeSBarry Smith If PetscLogPrintInfoNull is zero, no info messages associated with a null object are printed. 125c6c1daeSBarry Smith 135c6c1daeSBarry Smith If PetscInfoFlags[OBJECT_CLASSID - PETSC_SMALLEST_CLASSID] is zero, no messages related 145c6c1daeSBarry Smith to that object are printed. OBJECT_CLASSID is, for example, MAT_CLASSID. 155c6c1daeSBarry Smith */ 165c6c1daeSBarry Smith PetscBool PetscLogPrintInfo = PETSC_FALSE; 175c6c1daeSBarry Smith PetscBool PetscLogPrintInfoNull = PETSC_FALSE; 185c6c1daeSBarry Smith 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, 195c6c1daeSBarry Smith 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 205c6c1daeSBarry Smith 1,1,1,1,1,1,1,1,1,1,1,1}; 210298fd71SBarry Smith FILE *PetscInfoFile = NULL; 225c6c1daeSBarry Smith 235c6c1daeSBarry Smith #undef __FUNCT__ 245c6c1daeSBarry Smith #define __FUNCT__ "PetscInfoAllow" 255c6c1daeSBarry Smith /*@C 265c6c1daeSBarry Smith PetscInfoAllow - Causes PetscInfo() messages to be printed to standard output. 275c6c1daeSBarry Smith 285c6c1daeSBarry Smith Not Collective, each processor may call this separately, but printing is only 295c6c1daeSBarry Smith turned on if the lowest processor number associated with the PetscObject associated 305c6c1daeSBarry Smith with the call to PetscInfo() has called this routine. 315c6c1daeSBarry Smith 325c6c1daeSBarry Smith Input Parameter: 335c6c1daeSBarry Smith + flag - PETSC_TRUE or PETSC_FALSE 345c6c1daeSBarry Smith - filename - optional name of file to write output to (defaults to stdout) 355c6c1daeSBarry Smith 365c6c1daeSBarry Smith Options Database Key: 375c6c1daeSBarry Smith . -info [optional filename] - Activates PetscInfoAllow() 385c6c1daeSBarry Smith 395c6c1daeSBarry Smith Level: advanced 405c6c1daeSBarry Smith 415c6c1daeSBarry Smith Concepts: debugging^detailed runtime information 425c6c1daeSBarry Smith Concepts: dumping detailed runtime information 435c6c1daeSBarry Smith 445c6c1daeSBarry Smith .seealso: PetscInfo() 455c6c1daeSBarry Smith @*/ 465c6c1daeSBarry Smith PetscErrorCode PetscInfoAllow(PetscBool flag, const char filename[]) 475c6c1daeSBarry Smith { 485c6c1daeSBarry Smith char fname[PETSC_MAX_PATH_LEN], tname[5]; 495c6c1daeSBarry Smith PetscMPIInt rank; 505c6c1daeSBarry Smith PetscErrorCode ierr; 515c6c1daeSBarry Smith 525c6c1daeSBarry Smith PetscFunctionBegin; 535c6c1daeSBarry Smith if (flag && filename) { 545c6c1daeSBarry Smith ierr = PetscFixFilename(filename, fname);CHKERRQ(ierr); 555c6c1daeSBarry Smith ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);CHKERRQ(ierr); 565c6c1daeSBarry Smith sprintf(tname, ".%d", rank); 575c6c1daeSBarry Smith ierr = PetscStrcat(fname, tname);CHKERRQ(ierr); 585c6c1daeSBarry Smith ierr = PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscInfoFile);CHKERRQ(ierr); 595c6c1daeSBarry Smith if (!PetscInfoFile) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname); 60a297a907SKarl Rupp } else if (flag) PetscInfoFile = PETSC_STDOUT; 61a297a907SKarl Rupp 625c6c1daeSBarry Smith PetscLogPrintInfo = flag; 635c6c1daeSBarry Smith PetscLogPrintInfoNull = flag; 645c6c1daeSBarry Smith PetscFunctionReturn(0); 655c6c1daeSBarry Smith } 665c6c1daeSBarry Smith 675c6c1daeSBarry Smith #undef __FUNCT__ 685c6c1daeSBarry Smith #define __FUNCT__ "PetscInfoDeactivateClass" 695c6c1daeSBarry Smith /*@ 705c6c1daeSBarry Smith PetscInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class. 715c6c1daeSBarry Smith 725c6c1daeSBarry Smith Not Collective 735c6c1daeSBarry Smith 745c6c1daeSBarry Smith Input Parameter: 755c6c1daeSBarry Smith . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc. 765c6c1daeSBarry Smith 775c6c1daeSBarry Smith Notes: 785c6c1daeSBarry Smith One can pass 0 to deactivate all messages that are not associated with an object. 795c6c1daeSBarry Smith 805c6c1daeSBarry Smith Level: developer 815c6c1daeSBarry Smith 825c6c1daeSBarry Smith .keywords: allow, information, printing, monitoring 835c6c1daeSBarry Smith .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow() 845c6c1daeSBarry Smith @*/ 855c6c1daeSBarry Smith PetscErrorCode PetscInfoDeactivateClass(int objclass) 865c6c1daeSBarry Smith { 875c6c1daeSBarry Smith PetscFunctionBegin; 885c6c1daeSBarry Smith if (!objclass) { 895c6c1daeSBarry Smith PetscLogPrintInfoNull = PETSC_FALSE; 905c6c1daeSBarry Smith PetscFunctionReturn(0); 915c6c1daeSBarry Smith } 925c6c1daeSBarry Smith PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 0; 935c6c1daeSBarry Smith PetscFunctionReturn(0); 945c6c1daeSBarry Smith } 955c6c1daeSBarry Smith 965c6c1daeSBarry Smith #undef __FUNCT__ 975c6c1daeSBarry Smith #define __FUNCT__ "PetscInfoActivateClass" 985c6c1daeSBarry Smith /*@ 995c6c1daeSBarry Smith PetscInfoActivateClass - Activates PlogInfo() messages for a PETSc object class. 1005c6c1daeSBarry Smith 1015c6c1daeSBarry Smith Not Collective 1025c6c1daeSBarry Smith 1035c6c1daeSBarry Smith Input Parameter: 1045c6c1daeSBarry Smith . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc. 1055c6c1daeSBarry Smith 1065c6c1daeSBarry Smith Notes: 1075c6c1daeSBarry Smith One can pass 0 to activate all messages that are not associated with an object. 1085c6c1daeSBarry Smith 1095c6c1daeSBarry Smith Level: developer 1105c6c1daeSBarry Smith 1115c6c1daeSBarry Smith .keywords: allow, information, printing, monitoring 1125c6c1daeSBarry Smith .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow() 1135c6c1daeSBarry Smith @*/ 1145c6c1daeSBarry Smith PetscErrorCode PetscInfoActivateClass(int objclass) 1155c6c1daeSBarry Smith { 1165c6c1daeSBarry Smith PetscFunctionBegin; 117a297a907SKarl Rupp if (!objclass) PetscLogPrintInfoNull = PETSC_TRUE; 118a297a907SKarl Rupp else PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 1; 1195c6c1daeSBarry Smith PetscFunctionReturn(0); 1205c6c1daeSBarry Smith } 1215c6c1daeSBarry Smith 1225c6c1daeSBarry Smith /* 1235c6c1daeSBarry Smith If the option -history was used, then all printed PetscInfo() 1245c6c1daeSBarry Smith messages are also printed to the history file, called by default 1255c6c1daeSBarry Smith .petschistory in ones home directory. 1265c6c1daeSBarry Smith */ 1275c6c1daeSBarry Smith extern FILE *petsc_history; 1285c6c1daeSBarry Smith 1295c6c1daeSBarry Smith #undef __FUNCT__ 1305c6c1daeSBarry Smith #define __FUNCT__ "PetscInfo_Private" 1315c6c1daeSBarry Smith /*MC 1325c6c1daeSBarry Smith PetscInfo - Logs informative data, which is printed to standard output 1335c6c1daeSBarry Smith or a file when the option -info <file> is specified. 1345c6c1daeSBarry Smith 1355c6c1daeSBarry Smith Synopsis: 136*aaa7dc30SBarry Smith #include <petscsys.h> 1375c6c1daeSBarry Smith PetscErrorCode PetscInfo(void *vobj, const char message[]) 1385c6c1daeSBarry Smith PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1) 1395c6c1daeSBarry Smith PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2) 1405c6c1daeSBarry Smith etc 1415c6c1daeSBarry Smith 1425c6c1daeSBarry Smith Collective over PetscObject argument 1435c6c1daeSBarry Smith 1445c6c1daeSBarry Smith Input Parameter: 1450298fd71SBarry Smith + vobj - object most closely associated with the logging statement or NULL 1465c6c1daeSBarry Smith . message - logging message 1475c6c1daeSBarry Smith - formatmessage - logging message using standard "printf" format 1485c6c1daeSBarry Smith 1495c6c1daeSBarry Smith Options Database Key: 1505c6c1daeSBarry Smith $ -info : activates printing of PetscInfo() messages 1515c6c1daeSBarry Smith 1525c6c1daeSBarry Smith Level: intermediate 1535c6c1daeSBarry Smith 1545c6c1daeSBarry Smith Fortran Note: This function does not take the vobj argument, there is only the PetscInfo() 1555c6c1daeSBarry Smith version, not PetscInfo1() etc. 1565c6c1daeSBarry Smith 1575c6c1daeSBarry Smith Example of Usage: 1585c6c1daeSBarry Smith $ 1595c6c1daeSBarry Smith $ Mat A 1605c6c1daeSBarry Smith $ double alpha 1615c6c1daeSBarry Smith $ PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha); 1625c6c1daeSBarry Smith $ 1635c6c1daeSBarry Smith 1645c6c1daeSBarry Smith Concepts: runtime information 1655c6c1daeSBarry Smith 1665c6c1daeSBarry Smith .seealso: PetscInfoAllow() 1675c6c1daeSBarry Smith M*/ 1685c6c1daeSBarry Smith PetscErrorCode PetscInfo_Private(const char func[],void *vobj, const char message[], ...) 1695c6c1daeSBarry Smith { 1705c6c1daeSBarry Smith va_list Argp; 1715c6c1daeSBarry Smith PetscMPIInt rank,urank; 1725c6c1daeSBarry Smith size_t len; 1735c6c1daeSBarry Smith PetscObject obj = (PetscObject)vobj; 1745c6c1daeSBarry Smith char string[8*1024]; 1755c6c1daeSBarry Smith PetscErrorCode ierr; 1765c6c1daeSBarry Smith size_t fullLength; 1775c6c1daeSBarry Smith int err; 1785c6c1daeSBarry Smith 1795c6c1daeSBarry Smith PetscFunctionBegin; 1805c6c1daeSBarry Smith if (obj) PetscValidHeader(obj,1); 1815c6c1daeSBarry Smith PetscValidCharPointer(message,2); 1825c6c1daeSBarry Smith if (!PetscLogPrintInfo) PetscFunctionReturn(0); 1835c6c1daeSBarry Smith if ((!PetscLogPrintInfoNull) && !vobj) PetscFunctionReturn(0); 1845c6c1daeSBarry Smith if (obj && !PetscInfoFlags[obj->classid - PETSC_SMALLEST_CLASSID - 1]) PetscFunctionReturn(0); 185a297a907SKarl Rupp if (!obj) rank = 0; 186a297a907SKarl Rupp else { 1875c6c1daeSBarry Smith ierr = MPI_Comm_rank(obj->comm, &rank);CHKERRQ(ierr); 1885c6c1daeSBarry Smith } 1895c6c1daeSBarry Smith if (rank) PetscFunctionReturn(0); 1905c6c1daeSBarry Smith 1915c6c1daeSBarry Smith ierr = MPI_Comm_rank(MPI_COMM_WORLD, &urank);CHKERRQ(ierr); 1925c6c1daeSBarry Smith va_start(Argp, message); 1935c6c1daeSBarry Smith sprintf(string, "[%d] %s(): ", urank,func); 1945c6c1daeSBarry Smith ierr = PetscStrlen(string, &len);CHKERRQ(ierr); 195a2ea699eSBarry Smith ierr = PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);CHKERRQ(ierr); 1965c6c1daeSBarry Smith ierr = PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);CHKERRQ(ierr); 1975c6c1daeSBarry Smith err = fflush(PetscInfoFile); 1985c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 1995c6c1daeSBarry Smith if (petsc_history) { 2005c6c1daeSBarry Smith va_start(Argp, message); 201a2ea699eSBarry Smith ierr = (*PetscVFPrintf)(petsc_history, message, Argp);CHKERRQ(ierr); 2025c6c1daeSBarry Smith } 2035c6c1daeSBarry Smith va_end(Argp); 2045c6c1daeSBarry Smith PetscFunctionReturn(0); 2055c6c1daeSBarry Smith } 206