Actual source code: ploginfo.c
1: /*
2: PetscLogInfo() is contained in a different file from the other profiling to
3: allow it to be replaced at link time by an alternative routine.
4: */
5: #include petsc.h
6: #include <stdarg.h>
7: #include <sys/types.h>
8: #include petscsys.h
9: #if defined(PETSC_HAVE_STDLIB_H)
10: #include <stdlib.h>
11: #endif
12: #if defined(PETSC_HAVE_MALLOC_H) && !defined(__cplusplus)
13: #include <malloc.h>
14: #endif
15: #include "petscfix.h"
17: /*
18: The next three variables determine which, if any, PetscLogInfo() calls are used.
19: If PetscLogPrintInfo is zero, no info messages are printed.
20: If PetscLogPrintInfoNull is zero, no info messages associated with a null object are printed.
22: If PetscLogInfoFlags[OBJECT_COOKIE - PETSC_COOKIE] is zero, no messages related
23: to that object are printed. OBJECT_COOKIE is, for example, MAT_COOKIE.
24: */
25: PetscTruth PetscLogPrintInfo = PETSC_FALSE;
26: PetscTruth PetscLogPrintInfoNull = PETSC_FALSE;
27: int PetscLogInfoFlags[] = {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,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};
30: FILE *PetscLogInfoFile = PETSC_NULL;
34: /*@C
35: PetscLogInfoAllow - Causes PetscLogInfo() messages to be printed to standard output.
37: Not Collective, each processor may call this seperately, but printing is only
38: turned on if the lowest processor number associated with the PetscObject associated
39: with the call to PetscLogInfo() has called this routine.
41: Input Parameter:
42: + flag - PETSC_TRUE or PETSC_FALSE
43: - filename - optional name of file to write output to (defaults to stdout)
45: Options Database Key:
46: . -log_info [optional filename] - Activates PetscLogInfoAllow()
48: Level: advanced
50: Concepts: debugging^detailed runtime information
51: Concepts: dumping detailed runtime information
53: .seealso: PetscLogInfo()
54: @*/
55: PetscErrorCode PetscLogInfoAllow(PetscTruth flag, const char filename[])
56: {
57: char fname[PETSC_MAX_PATH_LEN], tname[5];
58: PetscMPIInt rank;
62: if (flag && filename) {
63: PetscFixFilename(filename, fname);
64: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
65: sprintf(tname, ".%d", rank);
66: PetscStrcat(fname, tname);
67: PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscLogInfoFile);
68: if (!PetscLogInfoFile) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
69: } else if (flag) {
70: PetscLogInfoFile = stdout;
71: }
72: PetscLogPrintInfo = flag;
73: PetscLogPrintInfoNull = flag;
74: return(0);
75: }
79: /*@
80: PetscLogInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.
82: Not Collective
84: Input Parameter:
85: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
87: Notes:
88: One can pass 0 to deactivate all messages that are not associated with an object.
90: Level: developer
92: .keywords: allow, information, printing, monitoring
93: .seealso: PetscLogInfoActivateClass(), PetscLogInfo(), PetscLogInfoAllow()
94: @*/
95: PetscErrorCode PetscLogInfoDeactivateClass(int objclass)
96: {
98: if (!objclass) {
99: PetscLogPrintInfoNull = PETSC_FALSE;
100: return(0);
101: }
102: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 0;
103: return(0);
104: }
108: /*@
109: PetscLogInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.
111: Not Collective
113: Input Parameter:
114: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
116: Notes:
117: One can pass 0 to activate all messages that are not associated with an object.
119: Level: developer
121: .keywords: allow, information, printing, monitoring
122: .seealso: PetscLogInfoDeactivateClass(), PetscLogInfo(), PetscLogInfoAllow()
123: @*/
124: PetscErrorCode PetscLogInfoActivateClass(int objclass)
125: {
127: if (!objclass) {
128: PetscLogPrintInfoNull = PETSC_TRUE;
129: } else {
130: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 1;
131: }
132: return(0);
133: }
135: /*
136: If the option -log_history was used, then all printed PetscLogInfo()
137: messages are also printed to the history file, called by default
138: .petschistory in ones home directory.
139: */
144: /*@C
145: PetscLogInfo - Logs informative data, which is printed to standard output
146: or a file when the option -log_info <file> is specified.
148: Collective over PetscObject argument
150: Input Parameter:
151: + vobj - object most closely associated with the logging statement
152: - message - logging message, using standard "printf" format
154: Options Database Key:
155: $ -log_info : activates printing of PetscLogInfo() messages
157: Level: intermediate
159: Fortran Note:
160: This routine is not supported in Fortran.
162: Example of Usage:
163: $
164: $ Mat A
165: $ double alpha
166: $ PetscLogInfo(A,"Matrix uses parameter alpha=%g\n",alpha);
167: $
169: Concepts: runtime information
171: .seealso: PetscLogInfoAllow()
172: @*/
173: PetscErrorCode PetscLogInfo(void *vobj, const char message[], ...)
174: {
175: va_list Argp;
176: PetscMPIInt rank,urank;
177: size_t len;
178: PetscObject obj = (PetscObject)vobj;
179: char string[8*1024];
185: if (PetscLogPrintInfo == PETSC_FALSE) return(0);
186: if ((PetscLogPrintInfoNull == PETSC_FALSE) && !vobj) return(0);
187: if (obj && !PetscLogInfoFlags[obj->cookie - PETSC_COOKIE - 1]) return(0);
188: if (!obj) {
189: rank = 0;
190: } else {
191: MPI_Comm_rank(obj->comm, &rank);
192: }
193: if (rank) return(0);
195: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
196: va_start(Argp, message);
197: sprintf(string, "[%d]", urank);
198: PetscStrlen(string, &len);
199: PetscVSNPrintf(string+len, 8*1024-len,message, Argp);
200: PetscFPrintf(PETSC_COMM_SELF,PetscLogInfoFile, "%s", string);
201: fflush(PetscLogInfoFile);
202: if (petsc_history) {
203: PetscVFPrintf(petsc_history, message, Argp);
204: }
205: va_end(Argp);
206: return(0);
207: }