Actual source code: verboseinfo.c
1: #define PETSC_DLL
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.h
7: #include <stdarg.h>
8: #include <sys/types.h>
9: #include petscsys.h
10: #if defined(PETSC_HAVE_STDLIB_H)
11: #include <stdlib.h>
12: #endif
13: #if defined(PETSC_HAVE_MALLOC_H)
14: #include <malloc.h>
15: #endif
16: #include "petscfix.h"
18: /*
19: The next three variables determine which, if any, PetscInfo() calls are used.
20: If PetscLogPrintInfo is zero, no info messages are printed.
21: If PetscLogPrintInfoNull is zero, no info messages associated with a null object are printed.
23: If PetscInfoFlags[OBJECT_COOKIE - PETSC_SMALLEST_COOKIE] is zero, no messages related
24: to that object are printed. OBJECT_COOKIE is, for example, MAT_COOKIE.
25: */
26: PetscTruth PetscLogPrintInfo = PETSC_FALSE;
27: PetscTruth PetscLogPrintInfoNull = PETSC_FALSE;
28: 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,
29: 1,1,1,1,1,1,1,1,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};
31: FILE *PetscInfoFile = PETSC_NULL;
35: /*@C
36: PetscInfoAllow - Causes PetscInfo() messages to be printed to standard output.
38: Not Collective, each processor may call this separately, but printing is only
39: turned on if the lowest processor number associated with the PetscObject associated
40: with the call to PetscInfo() has called this routine.
42: Input Parameter:
43: + flag - PETSC_TRUE or PETSC_FALSE
44: - filename - optional name of file to write output to (defaults to stdout)
46: Options Database Key:
47: . -info [optional filename] - Activates PetscInfoAllow()
49: Level: advanced
51: Concepts: debugging^detailed runtime information
52: Concepts: dumping detailed runtime information
54: .seealso: PetscInfo()
55: @*/
56: PetscErrorCode PetscInfoAllow(PetscTruth flag, const char filename[])
57: {
58: char fname[PETSC_MAX_PATH_LEN], tname[5];
59: PetscMPIInt rank;
63: if (flag && filename) {
64: PetscFixFilename(filename, fname);
65: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
66: sprintf(tname, ".%d", rank);
67: PetscStrcat(fname, tname);
68: PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscInfoFile);
69: if (!PetscInfoFile) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
70: } else if (flag) {
71: PetscInfoFile = stdout;
72: }
73: PetscLogPrintInfo = flag;
74: PetscLogPrintInfoNull = flag;
75: return(0);
76: }
80: /*@
81: PetscInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.
83: Not Collective
85: Input Parameter:
86: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
88: Notes:
89: One can pass 0 to deactivate all messages that are not associated with an object.
91: Level: developer
93: .keywords: allow, information, printing, monitoring
94: .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow()
95: @*/
96: PetscErrorCode PetscInfoDeactivateClass(int objclass)
97: {
99: if (!objclass) {
100: PetscLogPrintInfoNull = PETSC_FALSE;
101: return(0);
102: }
103: PetscInfoFlags[objclass - PETSC_SMALLEST_COOKIE - 1] = 0;
104: return(0);
105: }
109: /*@
110: PetscInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.
112: Not Collective
114: Input Parameter:
115: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
117: Notes:
118: One can pass 0 to activate all messages that are not associated with an object.
120: Level: developer
122: .keywords: allow, information, printing, monitoring
123: .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow()
124: @*/
125: PetscErrorCode PetscInfoActivateClass(int objclass)
126: {
128: if (!objclass) {
129: PetscLogPrintInfoNull = PETSC_TRUE;
130: } else {
131: PetscInfoFlags[objclass - PETSC_SMALLEST_COOKIE - 1] = 1;
132: }
133: return(0);
134: }
136: /*
137: If the option -log_history was used, then all printed PetscInfo()
138: messages are also printed to the history file, called by default
139: .petschistory in ones home directory.
140: */
145: /*@C
146: PetscInfo - Logs informative data, which is printed to standard output
147: or a file when the option -info <file> is specified.
149: Collective over PetscObject argument
151: Synopsis:
152: PetscErrorCode PetscInfo(void *vobj, const char message[], ...))
154: Input Parameter:
155: + vobj - object most closely associated with the logging statement
156: - message - logging message, using standard "printf" format
158: Options Database Key:
159: $ -info : activates printing of PetscInfo() messages
161: Level: intermediate
163: Note: Since this is a macro you must wrap the arguments in TWO sets of (())
165: Fortran Note: This routine is not supported in Fortran.
167: Example of Usage:
168: $
169: $ Mat A
170: $ double alpha
171: $ PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha);
172: $
174: Concepts: runtime information
176: .seealso: PetscInfoAllow()
177: @*/
178: PetscErrorCode PetscInfo_Private(const char func[],void *vobj, const char message[], ...)
179: {
180: va_list Argp;
181: PetscMPIInt rank,urank;
182: size_t len;
183: PetscObject obj = (PetscObject)vobj;
184: char string[8*1024];
190: if (!PetscLogPrintInfo) return(0);
191: if ((!PetscLogPrintInfoNull) && !vobj) return(0);
192: if (obj && !PetscInfoFlags[obj->cookie - PETSC_SMALLEST_COOKIE - 1]) return(0);
193: if (!obj) {
194: rank = 0;
195: } else {
196: MPI_Comm_rank(obj->comm, &rank);
197: }
198: if (rank) return(0);
200: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
201: va_start(Argp, message);
202: sprintf(string, "[%d] %s(): ", urank,func);
203: PetscStrlen(string, &len);
204: PetscVSNPrintf(string+len, 8*1024-len,message, Argp);
205: PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);
206: fflush(PetscInfoFile);
207: if (petsc_history) {
208: PetscVFPrintf(petsc_history, message, Argp);
209: }
210: va_end(Argp);
211: return(0);
212: }