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 petscsys.h
7: #include <stdarg.h>
8: #include <sys/types.h>
9: #if defined(PETSC_HAVE_STDLIB_H)
10: #include <stdlib.h>
11: #endif
12: #if defined(PETSC_HAVE_MALLOC_H)
13: #include <malloc.h>
14: #endif
16: /*
17: The next three variables determine which, if any, PetscInfo() calls are used.
18: If PetscLogPrintInfo is zero, no info messages are printed.
19: If PetscLogPrintInfoNull is zero, no info messages associated with a null object are printed.
21: If PetscInfoFlags[OBJECT_COOKIE - PETSC_SMALLEST_COOKIE] is zero, no messages related
22: to that object are printed. OBJECT_COOKIE is, for example, MAT_COOKIE.
23: */
24: PetscTruth PetscLogPrintInfo = PETSC_FALSE;
25: PetscTruth PetscLogPrintInfoNull = PETSC_FALSE;
26: 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,
27: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
28: 1,1,1,1,1,1,1,1,1,1,1,1};
29: FILE *PetscInfoFile = PETSC_NULL;
33: /*@C
34: PetscInfoAllow - Causes PetscInfo() messages to be printed to standard output.
36: Not Collective, each processor may call this separately, but printing is only
37: turned on if the lowest processor number associated with the PetscObject associated
38: with the call to PetscInfo() has called this routine.
40: Input Parameter:
41: + flag - PETSC_TRUE or PETSC_FALSE
42: - filename - optional name of file to write output to (defaults to stdout)
44: Options Database Key:
45: . -info [optional filename] - Activates PetscInfoAllow()
47: Level: advanced
49: Concepts: debugging^detailed runtime information
50: Concepts: dumping detailed runtime information
52: .seealso: PetscInfo()
53: @*/
54: PetscErrorCode PetscInfoAllow(PetscTruth flag, const char filename[])
55: {
56: char fname[PETSC_MAX_PATH_LEN], tname[5];
57: PetscMPIInt rank;
61: if (flag && filename) {
62: PetscFixFilename(filename, fname);
63: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
64: sprintf(tname, ".%d", rank);
65: PetscStrcat(fname, tname);
66: PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscInfoFile);
67: if (!PetscInfoFile) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
68: } else if (flag) {
69: PetscInfoFile = PETSC_STDOUT;
70: }
71: PetscLogPrintInfo = flag;
72: PetscLogPrintInfoNull = flag;
73: return(0);
74: }
78: /*@
79: PetscInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.
81: Not Collective
83: Input Parameter:
84: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
86: Notes:
87: One can pass 0 to deactivate all messages that are not associated with an object.
89: Level: developer
91: .keywords: allow, information, printing, monitoring
92: .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow()
93: @*/
94: PetscErrorCode PetscInfoDeactivateClass(int objclass)
95: {
97: if (!objclass) {
98: PetscLogPrintInfoNull = PETSC_FALSE;
99: return(0);
100: }
101: PetscInfoFlags[objclass - PETSC_SMALLEST_COOKIE - 1] = 0;
102: return(0);
103: }
107: /*@
108: PetscInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.
110: Not Collective
112: Input Parameter:
113: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
115: Notes:
116: One can pass 0 to activate all messages that are not associated with an object.
118: Level: developer
120: .keywords: allow, information, printing, monitoring
121: .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow()
122: @*/
123: PetscErrorCode PetscInfoActivateClass(int objclass)
124: {
126: if (!objclass) {
127: PetscLogPrintInfoNull = PETSC_TRUE;
128: } else {
129: PetscInfoFlags[objclass - PETSC_SMALLEST_COOKIE - 1] = 1;
130: }
131: return(0);
132: }
134: /*
135: If the option -log_history was used, then all printed PetscInfo()
136: messages are also printed to the history file, called by default
137: .petschistory in ones home directory.
138: */
143: /*MC
144: PetscInfo - Logs informative data, which is printed to standard output
145: or a file when the option -info <file> is specified.
147: Collective over PetscObject argument
149: Synopsis:
150: PetscErrorCode PetscInfo(void *vobj, const char message[])
151: PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1)
152: PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2)
153: etc
155: Input Parameter:
156: + vobj - object most closely associated with the logging statement or PETSC_NULL
157: . message - logging message
158: - formatmessage - logging message using standard "printf" format
160: Options Database Key:
161: $ -info : activates printing of PetscInfo() messages
163: Level: intermediate
165: Fortran Note: This function does not take the vobj argument, there is only the PetscInfo()
166: version, not PetscInfo1() etc.
168: Example of Usage:
169: $
170: $ Mat A
171: $ double alpha
172: $ PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha);
173: $
175: Concepts: runtime information
177: .seealso: PetscInfoAllow()
178: M*/
179: PetscErrorCode PetscInfo_Private(const char func[],void *vobj, const char message[], ...)
180: {
181: va_list Argp;
182: PetscMPIInt rank,urank;
183: size_t len;
184: PetscObject obj = (PetscObject)vobj;
185: char string[8*1024];
187: int fullLength, err;
192: if (!PetscLogPrintInfo) return(0);
193: if ((!PetscLogPrintInfoNull) && !vobj) return(0);
194: if (obj && !PetscInfoFlags[obj->cookie - PETSC_SMALLEST_COOKIE - 1]) return(0);
195: if (!obj) {
196: rank = 0;
197: } else {
198: MPI_Comm_rank(obj->comm, &rank);
199: }
200: if (rank) return(0);
202: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
203: va_start(Argp, message);
204: sprintf(string, "[%d] %s(): ", urank,func);
205: PetscStrlen(string, &len);
206: PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);
207: PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);
208: err = fflush(PetscInfoFile);
209: if (err) SETERRQ(PETSC_ERR_SYS,"fflush() failed on file");
210: if (petsc_history) {
211: (*PetscVFPrintf)(petsc_history, message, Argp);
212: }
213: va_end(Argp);
214: return(0);
215: }