1 2 /* 3 PetscInfo() is contained in a different file from the other profiling to 4 allow it to be replaced at link time by an alternative routine. 5 */ 6 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 7 8 /* 9 The next three variables determine which, if any, PetscInfo() calls are used. 10 If PetscLogPrintInfo is zero, no info messages are printed. 11 If PetscLogPrintInfoNull is zero, no info messages associated with a null object are printed. 12 13 If PetscInfoFlags[OBJECT_CLASSID - PETSC_SMALLEST_CLASSID] is zero, no messages related 14 to that object are printed. OBJECT_CLASSID is, for example, MAT_CLASSID. 15 */ 16 PetscBool PetscLogPrintInfo = PETSC_FALSE; 17 PetscBool PetscLogPrintInfoNull = PETSC_FALSE; 18 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, 19 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 20 1,1,1,1,1,1,1,1,1,1,1,1}; 21 FILE *PetscInfoFile = NULL; 22 23 #undef __FUNCT__ 24 #define __FUNCT__ "PetscInfoAllow" 25 /*@C 26 PetscInfoAllow - Causes PetscInfo() messages to be printed to standard output. 27 28 Not Collective, each processor may call this separately, but printing is only 29 turned on if the lowest processor number associated with the PetscObject associated 30 with the call to PetscInfo() has called this routine. 31 32 Input Parameter: 33 + flag - PETSC_TRUE or PETSC_FALSE 34 - filename - optional name of file to write output to (defaults to stdout) 35 36 Options Database Key: 37 . -info [optional filename] - Activates PetscInfoAllow() 38 39 Level: advanced 40 41 Concepts: debugging^detailed runtime information 42 Concepts: dumping detailed runtime information 43 44 .seealso: PetscInfo() 45 @*/ 46 PetscErrorCode PetscInfoAllow(PetscBool flag, const char filename[]) 47 { 48 char fname[PETSC_MAX_PATH_LEN], tname[5]; 49 PetscMPIInt rank; 50 PetscErrorCode ierr; 51 52 PetscFunctionBegin; 53 if (flag && filename) { 54 ierr = PetscFixFilename(filename, fname);CHKERRQ(ierr); 55 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);CHKERRQ(ierr); 56 sprintf(tname, ".%d", rank); 57 ierr = PetscStrcat(fname, tname);CHKERRQ(ierr); 58 ierr = PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscInfoFile);CHKERRQ(ierr); 59 if (!PetscInfoFile) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname); 60 } else if (flag) PetscInfoFile = PETSC_STDOUT; 61 62 PetscLogPrintInfo = flag; 63 PetscLogPrintInfoNull = flag; 64 PetscFunctionReturn(0); 65 } 66 67 #undef __FUNCT__ 68 #define __FUNCT__ "PetscInfoDeactivateClass" 69 /*@ 70 PetscInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class. 71 72 Not Collective 73 74 Input Parameter: 75 . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc. 76 77 Notes: 78 One can pass 0 to deactivate all messages that are not associated with an object. 79 80 Level: developer 81 82 .keywords: allow, information, printing, monitoring 83 .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow() 84 @*/ 85 PetscErrorCode PetscInfoDeactivateClass(int objclass) 86 { 87 PetscFunctionBegin; 88 if (!objclass) { 89 PetscLogPrintInfoNull = PETSC_FALSE; 90 PetscFunctionReturn(0); 91 } 92 PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 0; 93 PetscFunctionReturn(0); 94 } 95 96 #undef __FUNCT__ 97 #define __FUNCT__ "PetscInfoActivateClass" 98 /*@ 99 PetscInfoActivateClass - Activates PlogInfo() messages for a PETSc object class. 100 101 Not Collective 102 103 Input Parameter: 104 . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc. 105 106 Notes: 107 One can pass 0 to activate all messages that are not associated with an object. 108 109 Level: developer 110 111 .keywords: allow, information, printing, monitoring 112 .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow() 113 @*/ 114 PetscErrorCode PetscInfoActivateClass(int objclass) 115 { 116 PetscFunctionBegin; 117 if (!objclass) PetscLogPrintInfoNull = PETSC_TRUE; 118 else PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 1; 119 PetscFunctionReturn(0); 120 } 121 122 /* 123 If the option -history was used, then all printed PetscInfo() 124 messages are also printed to the history file, called by default 125 .petschistory in ones home directory. 126 */ 127 extern FILE *petsc_history; 128 129 #undef __FUNCT__ 130 #define __FUNCT__ "PetscInfo_Private" 131 /*MC 132 PetscInfo - Logs informative data, which is printed to standard output 133 or a file when the option -info <file> is specified. 134 135 Synopsis: 136 #include <petscsys.h> 137 PetscErrorCode PetscInfo(void *vobj, const char message[]) 138 PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1) 139 PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2) 140 etc 141 142 Collective over PetscObject argument 143 144 Input Parameter: 145 + vobj - object most closely associated with the logging statement or NULL 146 . message - logging message 147 - formatmessage - logging message using standard "printf" format 148 149 Options Database Key: 150 $ -info : activates printing of PetscInfo() messages 151 152 Level: intermediate 153 154 Fortran Note: This function does not take the vobj argument, there is only the PetscInfo() 155 version, not PetscInfo1() etc. 156 157 Example of Usage: 158 $ 159 $ Mat A 160 $ double alpha 161 $ PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha); 162 $ 163 164 Concepts: runtime information 165 166 .seealso: PetscInfoAllow() 167 M*/ 168 PetscErrorCode PetscInfo_Private(const char func[],void *vobj, const char message[], ...) 169 { 170 va_list Argp; 171 PetscMPIInt rank,urank; 172 size_t len; 173 PetscObject obj = (PetscObject)vobj; 174 char string[8*1024]; 175 PetscErrorCode ierr; 176 size_t fullLength; 177 int err; 178 179 PetscFunctionBegin; 180 if (obj) PetscValidHeader(obj,1); 181 PetscValidCharPointer(message,2); 182 if (!PetscLogPrintInfo) PetscFunctionReturn(0); 183 if ((!PetscLogPrintInfoNull) && !vobj) PetscFunctionReturn(0); 184 if (obj && !PetscInfoFlags[obj->classid - PETSC_SMALLEST_CLASSID - 1]) PetscFunctionReturn(0); 185 if (!obj) rank = 0; 186 else { 187 ierr = MPI_Comm_rank(obj->comm, &rank);CHKERRQ(ierr); 188 } 189 if (rank) PetscFunctionReturn(0); 190 191 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &urank);CHKERRQ(ierr); 192 va_start(Argp, message); 193 sprintf(string, "[%d] %s(): ", urank,func); 194 ierr = PetscStrlen(string, &len);CHKERRQ(ierr); 195 ierr = PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);CHKERRQ(ierr); 196 ierr = PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);CHKERRQ(ierr); 197 err = fflush(PetscInfoFile); 198 if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 199 if (petsc_history) { 200 va_start(Argp, message); 201 ierr = (*PetscVFPrintf)(petsc_history, message, Argp);CHKERRQ(ierr); 202 } 203 va_end(Argp); 204 PetscFunctionReturn(0); 205 } 206