Actual source code: verboseinfo.c

petsc-3.9.0 2018-04-07
Report Typos and Errors

  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>

  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.

 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;

 23: /*@C
 24:     PetscInfoAllow - Causes PetscInfo() messages to be printed to standard output.

 26:     Not Collective, each processor may call this separately, but printing is only
 27:     turned on if the lowest processor number associated with the PetscObject associated
 28:     with the call to PetscInfo() has called this routine.

 30:     Input Parameter:
 31: +   flag - PETSC_TRUE or PETSC_FALSE
 32: -   filename - optional name of file to write output to (defaults to stdout)

 34:     Options Database Key:
 35: .   -info [optional filename] - Activates PetscInfoAllow()

 37:     Level: advanced

 39:    Concepts: debugging^detailed runtime information
 40:    Concepts: dumping detailed runtime information

 42: .seealso: PetscInfo()
 43: @*/
 44: PetscErrorCode  PetscInfoAllow(PetscBool flag, const char filename[])
 45: {
 46:   char           fname[PETSC_MAX_PATH_LEN], tname[5];
 47:   PetscMPIInt    rank;

 51:   if (flag && filename) {
 52:     PetscFixFilename(filename, fname);
 53:     MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
 54:     sprintf(tname, ".%d", rank);
 55:     PetscStrcat(fname, tname);
 56:     PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscInfoFile);
 57:     if (!PetscInfoFile) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
 58:   } else if (flag) PetscInfoFile = PETSC_STDOUT;

 60:   PetscLogPrintInfo     = flag;
 61:   PetscLogPrintInfoNull = flag;
 62:   return(0);
 63: }

 65: /*@
 66:   PetscInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.

 68:   Not Collective

 70:   Input Parameter:
 71: . objclass - The object class,  e.g., MAT_CLASSID, SNES_CLASSID, etc.

 73:   Notes:
 74:   One can pass 0 to deactivate all messages that are not associated with an object.

 76:   Level: developer

 78: .keywords: allow, information, printing, monitoring
 79: .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow()
 80: @*/
 81: PetscErrorCode  PetscInfoDeactivateClass(int objclass)
 82: {
 84:   if (!objclass) {
 85:     PetscLogPrintInfoNull = PETSC_FALSE;
 86:     return(0);
 87:   }
 88:   PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 0;
 89:   return(0);
 90: }

 92: /*@
 93:   PetscInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.

 95:   Not Collective

 97:   Input Parameter:
 98: . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc.

100:   Notes:
101:   One can pass 0 to activate all messages that are not associated with an object.

103:   Level: developer

105: .keywords: allow, information, printing, monitoring
106: .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow()
107: @*/
108: PetscErrorCode  PetscInfoActivateClass(int objclass)
109: {
111:   if (!objclass) PetscLogPrintInfoNull = PETSC_TRUE;
112:   else PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 1;
113:   return(0);
114: }

116: /*
117:    If the option -history was used, then all printed PetscInfo()
118:   messages are also printed to the history file, called by default
119:   .petschistory in ones home directory.
120: */
121: extern FILE *petsc_history;

123: /*MC
124:     PetscInfo - Logs informative data, which is printed to standard output
125:     or a file when the option -info <file> is specified.

127:    Synopsis:
128:        #include <petscsys.h>
129:        PetscErrorCode PetscInfo(void *vobj, const char message[])
130:        PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1)
131:        PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2)
132:        etc

134:     Collective over PetscObject argument

136:     Input Parameter:
137: +   vobj - object most closely associated with the logging statement or NULL
138: .   message - logging message
139: -   formatmessage - logging message using standard "printf" format

141:     Options Database Key:
142: $    -info : activates printing of PetscInfo() messages

144:     Level: intermediate

146:     Fortran Note: This function does not take the vobj argument, there is only the PetscInfo()
147:      version, not PetscInfo1() etc.

149:     Example of Usage:
150: $
151: $     Mat A
152: $     double alpha
153: $     PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha);
154: $

156:    Concepts: runtime information

158: .seealso: PetscInfoAllow()
159: M*/
160: PetscErrorCode  PetscInfo_Private(const char func[],void *vobj, const char message[], ...)
161: {
162:   va_list        Argp;
163:   PetscMPIInt    rank,urank;
164:   size_t         len;
165:   PetscObject    obj = (PetscObject)vobj;
166:   char           string[8*1024];
168:   size_t         fullLength;
169:   int            err;

174:   if (!PetscLogPrintInfo) return(0);
175:   if ((!PetscLogPrintInfoNull) && !vobj) return(0);
176:   if (obj && !PetscInfoFlags[obj->classid - PETSC_SMALLEST_CLASSID - 1]) return(0);
177:   if (!obj) rank = 0;
178:   else {
179:     MPI_Comm_rank(obj->comm, &rank);
180:   }
181:   if (rank) return(0);

183:   MPI_Comm_rank(MPI_COMM_WORLD, &urank);
184:   va_start(Argp, message);
185:   sprintf(string, "[%d] %s(): ", urank,func);
186:   PetscStrlen(string, &len);
187:   PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);
188:   PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);
189:   err  = fflush(PetscInfoFile);
190:   if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
191:   if (petsc_history) {
192:     va_start(Argp, message);
193:     (*PetscVFPrintf)(petsc_history, message, Argp);
194:   }
195:   va_end(Argp);
196:   return(0);
197: }