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 = PETSC_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: /*MC
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[])
153: PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1)
154: PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2)
155: etc
157: Input Parameter:
158: + vobj - object most closely associated with the logging statement or PETSC_NULL
159: . message - logging message
160: - formatmessage - logging message using standard "printf" format
162: Options Database Key:
163: $ -info : activates printing of PetscInfo() messages
165: Level: intermediate
167: Fortran Note: This function does not take the vobj argument, there is only the PetscInfo()
168: version, not PetscInfo1() etc.
170: Example of Usage:
171: $
172: $ Mat A
173: $ double alpha
174: $ PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha);
175: $
177: Concepts: runtime information
179: .seealso: PetscInfoAllow()
180: M*/
181: PetscErrorCode PetscInfo_Private(const char func[],void *vobj, const char message[], ...)
182: {
183: va_list Argp;
184: PetscMPIInt rank,urank;
185: size_t len;
186: PetscObject obj = (PetscObject)vobj;
187: char string[8*1024];
189: int fullLength, err;
194: if (!PetscLogPrintInfo) return(0);
195: if ((!PetscLogPrintInfoNull) && !vobj) return(0);
196: if (obj && !PetscInfoFlags[obj->cookie - PETSC_SMALLEST_COOKIE - 1]) return(0);
197: if (!obj) {
198: rank = 0;
199: } else {
200: MPI_Comm_rank(obj->comm, &rank);
201: }
202: if (rank) return(0);
204: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
205: va_start(Argp, message);
206: sprintf(string, "[%d] %s(): ", urank,func);
207: PetscStrlen(string, &len);
208: PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);
209: PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);
210: err = fflush(PetscInfoFile);
211: if (err) SETERRQ(PETSC_ERR_SYS,"fflush() failed on file");
212: if (petsc_history) {
213: (*PetscVFPrintf)(petsc_history, message, Argp);
214: }
215: va_end(Argp);
216: return(0);
217: }