Actual source code: ploginfo.c
1: /*$Id: ploginfo.c,v 1.22 2001/03/23 23:20:50 balay Exp $*/
2: /*
3: PetscLogInfo() 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) && !defined(__cplusplus)
14: #include <malloc.h>
15: #endif
16: #include "petscfix.h"
18: /*
19: The next three variables determine which, if any, PetscLogInfo() 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 PetscLogInfoFlags[OBJECT_COOKIE - PETSC_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 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,
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 *PetscLogInfoFile = PETSC_NULL;
33: /*@C
34: PetscLogInfoAllow - Causes PetscLogInfo() messages to be printed to standard output.
36: Not Collective, each processor may call this seperately, but printing is only
37: turned on if the lowest processor number associated with the PetscObject associated
38: with the call to PetscLogInfo() 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: . -log_info - Activates PetscLogInfoAllow()
47: Level: advanced
49: Concepts: debugging^detailed runtime information
50: Concepts: dumping detailed runtime information
52: .seealso: PetscLogInfo()
53: @*/
54: int PetscLogInfoAllow(PetscTruth flag, char *filename)
55: {
56: char fname[256], tname[5];
57: int rank;
58: int ierr;
61: PetscLogPrintInfo = flag;
62: PetscLogPrintInfoNull = flag;
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(PETSC_COMM_SELF, fname, "w", &PetscLogInfoFile);
69: if (PetscLogInfoFile == PETSC_NULL) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
70: } else if (flag) {
71: PetscLogInfoFile = stdout;
72: }
73: return(0);
74: }
76: /*@
77: PetscLogInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.
79: Not Collective
81: Input Parameter:
82: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
84: Notes:
85: One can pass 0 to deactivate all messages that are not associated with an object.
87: Level: developer
89: .keywords: allow, information, printing, monitoring
90: .seealso: PetscLogInfoActivateClass(), PetscLogInfo(), PetscLogInfoAllow()
91: @*/
92: int PetscLogInfoDeactivateClass(int objclass)
93: {
95: if (objclass == 0) {
96: PetscLogPrintInfoNull = PETSC_FALSE;
97: return(0);
98: }
99: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 0;
100: return(0);
101: }
103: /*@
104: PetscLogInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.
106: Not Collective
108: Input Parameter:
109: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
111: Notes:
112: One can pass 0 to activate all messages that are not associated with an object.
114: Level: developer
116: .keywords: allow, information, printing, monitoring
117: .seealso: PetscLogInfoDeactivateClass(), PetscLogInfo(), PetscLogInfoAllow()
118: @*/
119: int PetscLogInfoActivateClass(int objclass)
120: {
122: if (objclass == 0) {
123: PetscLogPrintInfoNull = PETSC_TRUE;
124: } else {
125: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 1;
126: }
127: return(0);
128: }
130: /*
131: If the option -log_history was used, then all printed PetscLogInfo()
132: messages are also printed to the history file, called by default
133: .petschistory in ones home directory.
134: */
135: extern FILE *petsc_history;
137: /*@C
138: PetscLogInfo - Logs informative data, which is printed to standard output
139: or a file when the option -log_info <file> is specified.
141: Collective over PetscObject argument
143: Input Parameter:
144: + vobj - object most closely associated with the logging statement
145: - message - logging message, using standard "printf" format
147: Options Database Key:
148: $ -log_info : activates printing of PetscLogInfo() messages
150: Level: intermediate
152: Fortran Note:
153: This routine is not supported in Fortran.
155: Example of Usage:
156: $
157: $ Mat A
158: $ double alpha
159: $ PetscLogInfo(A,"Matrix uses parameter alpha=%gn",alpha);
160: $
162: Concepts: runtime information
164: .seealso: PetscLogInfoAllow()
165: @*/
166: int PetscLogInfo(void *vobj, const char message[], ...)
167: {
168: va_list Argp;
169: int rank,urank,len;
170: PetscObject obj = (PetscObject)vobj;
171: char string[8*1024];
172: int ierr;
176: if (PetscLogPrintInfo == PETSC_FALSE) return(0);
177: if ((PetscLogPrintInfoNull == PETSC_FALSE) && !vobj) return(0);
178: if (obj && !PetscLogInfoFlags[obj->cookie - PETSC_COOKIE - 1]) return(0);
179: if (!obj) {
180: rank = 0;
181: } else {
182: MPI_Comm_rank(obj->comm, &rank);
183: }
184: if (rank) return(0);
186: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
187: va_start(Argp, message);
188: sprintf(string, "[%d]", urank);
189: PetscStrlen(string, &len);
190: #if defined(PETSC_HAVE_VPRINTF_CHAR)
191: vsprintf(string+len, message, (char *) Argp);
192: #else
193: vsprintf(string+len, message, Argp);
194: #endif
195: fprintf(PetscLogInfoFile, "%s", string);
196: fflush(PetscLogInfoFile);
197: if (petsc_history) {
198: #if defined(PETSC_HAVE_VPRINTF_CHAR)
199: vfprintf(petsc_history, message, (char *) Argp);
200: #else
201: vfprintf(petsc_history, message, Argp);
202: #endif
203: }
204: va_end(Argp);
205: return(0);
206: }