Actual source code: verboseinfo.c
petsc-3.6.1 2015-08-06
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> /*I "petscsys.h" I*/
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;
25: /*@C
26: PetscInfoAllow - Causes PetscInfo() messages to be printed to standard output.
28: Not Collective, each processor may call this separately, but printing is only
29: turned on if the lowest processor number associated with the PetscObject associated
30: with the call to PetscInfo() has called this routine.
32: Input Parameter:
33: + flag - PETSC_TRUE or PETSC_FALSE
34: - filename - optional name of file to write output to (defaults to stdout)
36: Options Database Key:
37: . -info [optional filename] - Activates PetscInfoAllow()
39: Level: advanced
41: Concepts: debugging^detailed runtime information
42: Concepts: dumping detailed runtime information
44: .seealso: PetscInfo()
45: @*/
46: PetscErrorCode PetscInfoAllow(PetscBool flag, const char filename[])
47: {
48: char fname[PETSC_MAX_PATH_LEN], tname[5];
49: PetscMPIInt rank;
53: if (flag && filename) {
54: PetscFixFilename(filename, fname);
55: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
56: sprintf(tname, ".%d", rank);
57: PetscStrcat(fname, tname);
58: PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscInfoFile);
59: if (!PetscInfoFile) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
60: } else if (flag) PetscInfoFile = PETSC_STDOUT;
62: PetscLogPrintInfo = flag;
63: PetscLogPrintInfoNull = flag;
64: return(0);
65: }
69: /*@
70: PetscInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.
72: Not Collective
74: Input Parameter:
75: . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc.
77: Notes:
78: One can pass 0 to deactivate all messages that are not associated with an object.
80: Level: developer
82: .keywords: allow, information, printing, monitoring
83: .seealso: PetscInfoActivateClass(), PetscInfo(), PetscInfoAllow()
84: @*/
85: PetscErrorCode PetscInfoDeactivateClass(int objclass)
86: {
88: if (!objclass) {
89: PetscLogPrintInfoNull = PETSC_FALSE;
90: return(0);
91: }
92: PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 0;
93: return(0);
94: }
98: /*@
99: PetscInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.
101: Not Collective
103: Input Parameter:
104: . objclass - The object class, e.g., MAT_CLASSID, SNES_CLASSID, etc.
106: Notes:
107: One can pass 0 to activate all messages that are not associated with an object.
109: Level: developer
111: .keywords: allow, information, printing, monitoring
112: .seealso: PetscInfoDeactivateClass(), PetscInfo(), PetscInfoAllow()
113: @*/
114: PetscErrorCode PetscInfoActivateClass(int objclass)
115: {
117: if (!objclass) PetscLogPrintInfoNull = PETSC_TRUE;
118: else PetscInfoFlags[objclass - PETSC_SMALLEST_CLASSID - 1] = 1;
119: return(0);
120: }
122: /*
123: If the option -history was used, then all printed PetscInfo()
124: messages are also printed to the history file, called by default
125: .petschistory in ones home directory.
126: */
127: extern FILE *petsc_history;
131: /*MC
132: PetscInfo - Logs informative data, which is printed to standard output
133: or a file when the option -info <file> is specified.
135: Synopsis:
136: #include <petscsys.h>
137: PetscErrorCode PetscInfo(void *vobj, const char message[])
138: PetscErrorCode PetscInfo1(void *vobj, const char formatmessage[],arg1)
139: PetscErrorCode PetscInfo2(void *vobj, const char formatmessage[],arg1,arg2)
140: etc
142: Collective over PetscObject argument
144: Input Parameter:
145: + vobj - object most closely associated with the logging statement or NULL
146: . message - logging message
147: - formatmessage - logging message using standard "printf" format
149: Options Database Key:
150: $ -info : activates printing of PetscInfo() messages
152: Level: intermediate
154: Fortran Note: This function does not take the vobj argument, there is only the PetscInfo()
155: version, not PetscInfo1() etc.
157: Example of Usage:
158: $
159: $ Mat A
160: $ double alpha
161: $ PetscInfo1(A,"Matrix uses parameter alpha=%g\n",alpha);
162: $
164: Concepts: runtime information
166: .seealso: PetscInfoAllow()
167: M*/
168: PetscErrorCode PetscInfo_Private(const char func[],void *vobj, const char message[], ...)
169: {
170: va_list Argp;
171: PetscMPIInt rank,urank;
172: size_t len;
173: PetscObject obj = (PetscObject)vobj;
174: char string[8*1024];
176: size_t fullLength;
177: int err;
182: if (!PetscLogPrintInfo) return(0);
183: if ((!PetscLogPrintInfoNull) && !vobj) return(0);
184: if (obj && !PetscInfoFlags[obj->classid - PETSC_SMALLEST_CLASSID - 1]) return(0);
185: if (!obj) rank = 0;
186: else {
187: MPI_Comm_rank(obj->comm, &rank);
188: }
189: if (rank) return(0);
191: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
192: va_start(Argp, message);
193: sprintf(string, "[%d] %s(): ", urank,func);
194: PetscStrlen(string, &len);
195: PetscVSNPrintf(string+len, 8*1024-len,message,&fullLength, Argp);
196: PetscFPrintf(PETSC_COMM_SELF,PetscInfoFile, "%s", string);
197: err = fflush(PetscInfoFile);
198: if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
199: if (petsc_history) {
200: va_start(Argp, message);
201: (*PetscVFPrintf)(petsc_history, message, Argp);
202: }
203: va_end(Argp);
204: return(0);
205: }