Actual source code: verboseinfo.c

petsc-3.10.5 2019-03-28
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.

 12:   If PetscInfoFlags[OBJECT_CLASSID - PETSC_SMALLEST_CLASSID] is zero, no messages related
 13:   to that object are printed. OBJECT_CLASSID is, for example, MAT_CLASSID.
 14: */
 15: PetscBool PetscLogPrintInfo = PETSC_FALSE;
 16: FILE     *PetscInfoFile     = NULL;
 17: int       PetscInfoFlags[]  = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 18:                                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,
 20:                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 21:                                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

 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[11];
 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:   return(0);
 62: }

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

 67:   Not Collective

 69:   Input Parameter:
 70: . classid - The object class,  e.g., MAT_CLASSID, SNES_CLASSID, etc.

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

 75:   Level: developer

 77: .keywords: allow, information, printing, monitoring
 78: .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow()
 79: @*/
 80: PetscErrorCode  PetscInfoDeactivateClass(PetscClassId classid)
 81: {
 83:   if (!classid) classid = PETSC_SMALLEST_CLASSID;
 84:   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 0;
 85:   return(0);
 86: }

 88: /*@
 89:   PetscInfoActivateClass - Activates PetscInfo() messages for a PETSc object class.

 91:   Not Collective

 93:   Input Parameter:
 94: . classid - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc.

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

 99:   Level: developer

101: .keywords: allow, information, printing, monitoring
102: .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow()
103: @*/
104: PetscErrorCode  PetscInfoActivateClass(PetscClassId classid)
105: {
107:   if (!classid) classid = PETSC_SMALLEST_CLASSID;
108:   PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID] = 1;
109:   return(0);
110: }

112: /*
113:    If the option -history was used, then all printed PetscInfo()
114:   messages are also printed to the history file, called by default
115:   .petschistory in ones home directory.
116: */
117: PETSC_INTERN FILE *petsc_history;

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

123:    Synopsis:
124:        #include <petscsys.h>
125:        PetscErrorCode PetscInfo(void *vobj, const char message[])
126:        PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1)
127:        PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2)
128:        etc

130:     Collective over PetscObject argument

132:     Input Parameter:
133: +   vobj - object most closely associated with the logging statement or NULL
134: .   message - logging message
135: -   formatmessage - logging message using standard "printf" format

137:     Options Database Key:
138: $    -info : activates printing of PetscInfo() messages

140:     Level: intermediate

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

145:     Example of Usage:
146: $
147: $     Mat A
148: $     double alpha
149: $     PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha);
150: $

152:    Concepts: runtime information

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

171:   if (!PetscLogPrintInfo) return(0);
172:   classid = obj ? obj->classid : PETSC_SMALLEST_CLASSID;
173:   if (!PetscInfoFlags[classid - PETSC_SMALLEST_CLASSID]) return(0);
174:   if (obj) {MPI_Comm_rank(obj->comm, &rank);}
175:   if (rank) return(0);

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