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: #undef __FUNCT__
35: /*@C
36: PetscLogInfoAllow - Causes PetscLogInfo() messages to be printed to standard output.
38: Not Collective, each processor may call this seperately, but printing is only
39: turned on if the lowest processor number associated with the PetscObject associated
40: with the call to PetscLogInfo() 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: . -log_info [optional filename] - Activates PetscLogInfoAllow()
49: Level: advanced
51: Concepts: debugging^detailed runtime information
52: Concepts: dumping detailed runtime information
54: .seealso: PetscLogInfo()
55: @*/
56: int PetscLogInfoAllow(PetscTruth flag, char *filename)
57: {
58: char fname[PETSC_MAX_PATH_LEN], tname[5];
59: int rank;
60: int ierr;
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", &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: PetscLogPrintInfo = flag;
74: PetscLogPrintInfoNull = flag;
75: return(0);
76: }
78: #undef __FUNCT__
80: /*@
81: PetscLogInfoDeactivateClass - 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: PetscLogInfoActivateClass(), PetscLogInfo(), PetscLogInfoAllow()
95: @*/
96: int PetscLogInfoDeactivateClass(int objclass)
97: {
99: if (objclass == 0) {
100: PetscLogPrintInfoNull = PETSC_FALSE;
101: return(0);
102: }
103: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 0;
104: return(0);
105: }
107: #undef __FUNCT__
109: /*@
110: PetscLogInfoActivateClass - 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: PetscLogInfoDeactivateClass(), PetscLogInfo(), PetscLogInfoAllow()
124: @*/
125: int PetscLogInfoActivateClass(int objclass)
126: {
128: if (objclass == 0) {
129: PetscLogPrintInfoNull = PETSC_TRUE;
130: } else {
131: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 1;
132: }
133: return(0);
134: }
136: /*
137: If the option -log_history was used, then all printed PetscLogInfo()
138: messages are also printed to the history file, called by default
139: .petschistory in ones home directory.
140: */
141: extern FILE *petsc_history;
143: #undef __FUNCT__
145: /*@C
146: PetscLogInfo - Logs informative data, which is printed to standard output
147: or a file when the option -log_info <file> is specified.
149: Collective over PetscObject argument
151: Input Parameter:
152: + vobj - object most closely associated with the logging statement
153: - message - logging message, using standard "printf" format
155: Options Database Key:
156: $ -log_info : activates printing of PetscLogInfo() messages
158: Level: intermediate
160: Fortran Note:
161: This routine is not supported in Fortran.
163: Example of Usage:
164: $
165: $ Mat A
166: $ double alpha
167: $ PetscLogInfo(A,"Matrix uses parameter alpha=%gn",alpha);
168: $
170: Concepts: runtime information
172: .seealso: PetscLogInfoAllow()
173: @*/
174: int PetscLogInfo(void *vobj, const char message[], ...)
175: {
176: va_list Argp;
177: int rank,urank,len;
178: PetscObject obj = (PetscObject)vobj;
179: char string[8*1024];
180: int ierr;
184: if (PetscLogPrintInfo == PETSC_FALSE) return(0);
185: if ((PetscLogPrintInfoNull == PETSC_FALSE) && !vobj) return(0);
186: if (obj && !PetscLogInfoFlags[obj->cookie - PETSC_COOKIE - 1]) return(0);
187: if (!obj) {
188: rank = 0;
189: } else {
190: MPI_Comm_rank(obj->comm, &rank);
191: }
192: if (rank) return(0);
194: MPI_Comm_rank(MPI_COMM_WORLD, &urank);
195: va_start(Argp, message);
196: sprintf(string, "[%d]", urank);
197: PetscStrlen(string, &len);
198: #if defined(PETSC_HAVE_VPRINTF_CHAR)
199: vsprintf(string+len, message, (char *) Argp);
200: #else
201: vsprintf(string+len, message, Argp);
202: #endif
203: fprintf(PetscLogInfoFile, "%s", string);
204: fflush(PetscLogInfoFile);
205: if (petsc_history) {
206: #if defined(PETSC_HAVE_VPRINTF_CHAR)
207: vfprintf(petsc_history, message, (char *) Argp);
208: #else
209: vfprintf(petsc_history, message, Argp);
210: #endif
211: }
212: va_end(Argp);
213: return(0);
214: }