xref: /petsc/include/petsclog.h (revision 912ebf9aa32cd6ffee33ffd0333e9b4fec2e8450)
1 /* $Id: petsclog.h,v 1.103 1997/03/06 21:38:32 balay Exp bsmith $ */
2 
3 /*
4     Defines profile/logging in PETSc.
5 */
6 
7 #if !defined(__PLOG_PACKAGE)
8 #define __PLOG_PACKAGE
9 #include "petsc.h"
10 
11 typedef double PLogDouble;
12 
13 /*
14   Lists all PETSc events that are logged/profiled.
15 
16   If you add an event here, make sure you add it to
17   petsc/bin/petscview.cfg,
18   petsc/bin/petscview,
19   petsc/src/plog/src/plog.c,
20   petsc/src/plog/src/plogmpe.c and
21   petsc/include/FINCLUDE/petsclog.h!!!
22 */
23 #define MAT_Mult                                0
24 #define MAT_MatrixFreeMult                      1
25 #define MAT_AssemblyBegin                       2
26 #define MAT_AssemblyEnd                         3
27 #define MAT_GetReordering                       4
28 #define MAT_MultTrans                           5
29 #define MAT_MultAdd                             6
30 #define MAT_MultTransAdd                        7
31 #define MAT_LUFactor                            8
32 #define MAT_CholeskyFactor                      9
33 #define MAT_LUFactorSymbolic                    10
34 #define MAT_ILUFactorSymbolic                   11
35 #define MAT_CholeskyFactorSymbolic              12
36 #define MAT_IncompleteCholeskyFactorSymbolic    13
37 #define MAT_LUFactorNumeric                     14
38 #define MAT_CholeskyFactorNumeric               15
39 #define MAT_Relax                               16
40 #define MAT_Copy                                17
41 #define MAT_Convert                             18
42 #define MAT_Scale                               19
43 #define MAT_ZeroEntries                         20
44 #define MAT_Solve                               21
45 #define MAT_SolveAdd                            22
46 #define MAT_SolveTrans                          23
47 #define MAT_SolveTransAdd                       24
48 #define MAT_SetValues                           25
49 #define MAT_ForwardSolve                        26
50 #define MAT_BackwardSolve                       27
51 #define MAT_Load                                28
52 #define MAT_View                                29
53 #define MAT_ILUFactor                           30
54 #define MAT_GetColoring                         31
55 #define MAT_GetSubMatrices                      32
56 #define MAT_GetValues                           33
57 #define MAT_IncreaseOverlap                     34
58 #define MAT_GetRow                              35
59 
60 #define VEC_Dot                                 40
61 #define VEC_Norm                                41
62 #define VEC_Max                                 42
63 #define VEC_Min                                 43
64 #define VEC_TDot                                44
65 #define VEC_Scale                               45
66 #define VEC_Copy                                46
67 #define VEC_Set                                 47
68 #define VEC_AXPY                                48
69 #define VEC_AYPX                                49
70 #define VEC_Swap                                50
71 #define VEC_WAXPY                               51
72 #define VEC_AssemblyBegin                       52
73 #define VEC_AssemblyEnd                         53
74 #define VEC_MTDot                               54
75 #define VEC_MDot                                55
76 #define VEC_MAXPY                               56
77 #define VEC_PMult                               57
78 #define VEC_SetValues                           58
79 #define VEC_Load                                59
80 #define VEC_View                                60
81 #define VEC_ScatterBegin                        61
82 #define VEC_ScatterEnd                          62
83 #define VEC_SetRandom                           63
84 
85 #define SLES_Solve                              70
86 #define SLES_SetUp                              71
87 
88 #define KSP_GMRESOrthogonalization              72
89 
90 #define PC_ModifySubMatrices                    74
91 #define PC_SetUp                                75
92 #define PC_SetUpOnBlocks                        76
93 #define PC_Apply                                77
94 #define PC_ApplySymmetricLeft                   78
95 #define PC_ApplySymmetricRight                  79
96 
97 #define SNES_Solve                              80
98 #define SNES_LineSearch                         81
99 #define SNES_FunctionEval                       82
100 #define SNES_JacobianEval                       83
101 #define SNES_MinimizationFunctionEval           84
102 #define SNES_GradientEval                       85
103 #define SNES_HessianEval                        86
104 
105 #define TS_Step                                 90
106 #define TS_PseudoComputeTimeStep                91
107 
108 #define Petsc_Barrier                           100
109 
110 #define EC_SetUp                                105
111 #define EC_Solve                                106
112 
113 #define DFVec_RefineVector                      110
114 #define DFVec_AssembleFullVector                111
115 #define DFVec_GetComponentVectors               112
116 #define DFVec_DrawContours                      113
117 
118 /*
119    Event numbers PLOG_USER_EVENT_LOW to PLOG_USER_EVENT_HIGH are reserved
120    for applications.  Make sure that src/plog/src/plog.c defines enough
121    entries in (*name)[] to go up to PLOG_USER_EVENT_HIGH.
122 */
123 #define PLOG_USER_EVENT_LOW_STATIC              120
124 #define PLOG_USER_EVENT_HIGH                    200
125 
126 /* Global flop counter */
127 extern PLogDouble _TotalFlops;
128 
129 /* General logging of information; different from event logging */
130 extern int PLogInfo(void*,char*,...);
131 extern int PLogInfoDeactivateClass(int);
132 extern int PLogInfoActivateClass(int);
133 extern int PLogPrintInfo;  /* if 1, indicates PLogInfo() is turned on */
134 
135 #if defined(PETSC_LOG)  /* --------------------------------------------*/
136 
137 #define PLogFlops(n) {_TotalFlops += (n);}
138 
139 #if defined (HAVE_MPE)
140 #include "mpe.h"
141 #define MPEBEGIN    1000
142 extern int PLogMPEBegin();
143 extern int PLogMPEDump(char *);
144 extern int UseMPE,PLogEventMPEFlags[];
145 extern int PLogEventMPEActivate(int);
146 extern int PLogEventMPEDeactivate(int);
147 #else
148 #define PLogEventMPEActivate(a) 0
149 #define PLogEventMPEDeactivate(a) 0
150 #endif
151 
152 extern int PLogEventActivate(int);
153 extern int PLogEventDeactivate(int);
154 
155 extern int PLogEventActivateClass(int);
156 extern int PLogEventDeactivateClass(int);
157 
158 extern int PLogEventFlags[];
159 extern int (*_PLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
160 extern int (*_PLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
161 extern int (*_PLogPHC)(PetscObject);
162 extern int (*_PLogPHD)(PetscObject);
163 
164 #if defined(HAVE_MPE)
165 #define PLogEventBegin(e,o1,o2,o3,o4) {static int _tacky = 0; \
166   { _tacky++; \
167    if (_PLogPLB && PLogEventFlags[e]) \
168      (*_PLogPLB)(e,_tacky,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
169    if (_tacky == 1 && UseMPE && PLogEventMPEFlags[e])\
170      MPE_Log_event(MPEBEGIN+2*e,0,"");\
171   }
172 #else
173 #define PLogEventBegin(e,o1,o2,o3,o4) {static int _tacky = 0; \
174   { _tacky++; \
175    if (_PLogPLB && PLogEventFlags[e]) \
176      (*_PLogPLB)(e,_tacky,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
177   }
178 #endif
179 
180 #if defined(HAVE_MPE)
181 #define PLogEventEnd(e,o1,o2,o3,o4) {\
182   if (_PLogPLE && PLogEventFlags[e]) \
183     (*_PLogPLE)(e,_tacky,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
184   if (_tacky == 1 && UseMPE && PLogEventMPEFlags[e])\
185      MPE_Log_event(MPEBEGIN+2*e+1,0,"");\
186   }  _tacky--;}
187 #else
188 #define PLogEventEnd(e,o1,o2,o3,o4) {\
189   if (_PLogPLE && PLogEventFlags[e]) \
190     (*_PLogPLE)(e,_tacky,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
191   } _tacky--;}
192 #endif
193 
194 
195 #define PLogObjectParent(p,c)       {PetscValidHeader((PetscObject)c); \
196                                      PetscValidHeader((PetscObject)p);\
197                                      ((PetscObject)(c))->parent = (PetscObject) p;}
198 #define PLogObjectParents(p,n,d)    {int _i; for ( _i=0; _i<n; _i++ ) \
199                                     PLogObjectParent(p,(d)[_i]);}
200 #define PLogObjectCreate(h)         {if (_PLogPHC) (*_PLogPHC)((PetscObject)h);}
201 #define PLogObjectDestroy(h)        {if (_PLogPHD) (*_PLogPHD)((PetscObject)h);}
202 #define PLogObjectMemory(p,m)       {PetscValidHeader((PetscObject)p);\
203                                     ((PetscObject)(p))->mem += (m);}
204 extern int        PLogObjectState(PetscObject,char *,...);
205 extern int        PLogDestroy();
206 extern int        PLogStagePush(int);
207 extern int        PLogStagePop();
208 extern int        PLogStageRegister(int,char*);
209 extern int        PLogPrintSummary(MPI_Comm,char *);
210 extern int        PLogBegin();
211 extern int        PLogTraceBegin(FILE *);
212 extern int        PLogAllBegin();
213 extern int        PLogSet(int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject),
214                           int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject));
215 extern int        PLogDump(char*);
216 extern int        PLogEventRegister(int*,char*,char*);
217 extern PLogDouble PetscGetFlops();
218 
219 extern PLogDouble irecv_ct, isend_ct, wait_ct, wait_any_ct, recv_ct, send_ct;
220 extern PLogDouble irecv_len, isend_len, recv_len, send_len;
221 extern PLogDouble wait_all_ct,allreduce_ct,sum_of_waits_ct;
222 /*
223      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
224    uses macros to defined the MPI operations.
225 
226      It does not work correctly from HP-UX because it processes the
227    macros in a way that sometimes it double counts.
228 
229      It does not work with Windows NT because winmpich lacks MPI_Type_size()
230 */
231 #if !defined(PETSC_USING_MPIUNI) && !defined(PARCH_hpux) && !defined (PARCH_nt)
232 /*
233    Logging of MPI activities
234 */
235 
236 #define TypeSize(buff,count,type)                                            \
237 {                                                                            \
238   if (type == MPIU_SCALAR) {                                                 \
239     buff += (PLogDouble) ((count)*sizeof(Scalar));                               \
240   } else if (type == MPI_INT) {                                              \
241     buff += (PLogDouble) ((count)*sizeof(int));                                  \
242   } else {                                                                   \
243     int _size; MPI_Type_size(type,&_size); buff += (PLogDouble) ((count)*_size); \
244   }                                                                          \
245 }
246 
247 #define MPI_Irecv( buf, count,  datatype, source, tag, comm, request)        \
248 {                                                                            \
249   MPI_Irecv( buf, count,  datatype, source, tag, comm, request);             \
250   irecv_ct++; TypeSize(irecv_len,count,datatype);                            \
251 }
252 
253 #define MPI_Isend( buf, count,  datatype, dest, tag, comm, request)          \
254 {                                                                            \
255   MPI_Isend( buf, count,  datatype, dest, tag, comm, request);               \
256   isend_ct++;   TypeSize(isend_len,count,datatype);                          \
257 }
258 
259 #define MPI_Startall_irecv( count,number,requests)                            \
260 {                                                                             \
261   MPI_Startall( number, requests);                                            \
262   irecv_ct += (PLogDouble)(number); irecv_len += (PLogDouble) (count*sizeof(Scalar)); \
263 }
264 
265 #define MPI_Startall_isend( count,number,requests)                            \
266 {                                                                             \
267   MPI_Startall( number, requests);                                            \
268   isend_ct += (PLogDouble)(number); isend_len += (PLogDouble) (count*sizeof(Scalar)); \
269 }
270 
271 #define MPI_Start_isend(count,  requests)                                     \
272 {                                                                             \
273   MPI_Start( requests);                                                       \
274   isend_ct++; isend_len += (PLogDouble) (count*sizeof(Scalar));                   \
275 }
276 
277 #define MPI_Recv( buf, count,  datatype, source, tag, comm, status)           \
278 {                                                                             \
279   MPI_Recv( buf, count,  datatype, source, tag, comm, status);                \
280   recv_ct++; TypeSize(recv_len,count,datatype);                               \
281 }
282 
283 #define MPI_Send( buf, count,  datatype, dest, tag, comm)                     \
284 {                                                                             \
285   MPI_Send( buf, count,  datatype, dest, tag, comm);                          \
286   send_ct++;  TypeSize(send_len,count,datatype);                              \
287 }
288 
289 #define MPI_Wait(request, status) \
290 (                                 \
291   wait_ct++, sum_of_waits_ct++,   \
292   MPI_Wait(request, status)       \
293 )
294 
295 #define MPI_Waitany(a, b, c, d)     \
296 (                                   \
297   wait_any_ct++, sum_of_waits_ct++, \
298   MPI_Waitany(a, b, c, d)           \
299 )
300 
301 #define MPI_Waitall(count, array_of_requests, array_of_statuses) \
302 (                                                                \
303   wait_all_ct++, sum_of_waits_ct += (PLogDouble) (count),            \
304   MPI_Waitall(count, array_of_requests, array_of_statuses)       \
305 )
306 
307 #define MPI_Allreduce( sendbuf,  recvbuf, count, datatype, op, comm) \
308 (                                                                    \
309   allreduce_ct++,                                                    \
310   MPI_Allreduce( sendbuf,  recvbuf, count, datatype, op, comm)       \
311 )
312 #else
313 
314 #define MPI_Startall_irecv( count,number,requests) \
315 {                                                  \
316   MPI_Startall( number, requests);                 \
317 }
318 
319 #define MPI_Startall_isend( count,number,requests) \
320 {                                                  \
321   MPI_Startall( number, requests);                 \
322 }
323 
324 #define MPI_Start_isend(count,  requests) \
325 {                                         \
326   MPI_Start( requests);                   \
327 }
328 
329 #endif /* ! PETSC_USING_MPIUNI && ! PARCH_hpux */
330 
331 #else  /* ------------------------------------------------------------*/
332 
333 #define PLogFlops(n)
334 
335 #if defined (HAVE_MPE)
336 #define MPEBEGIN    1000
337 extern int PLogMPEBegin();
338 extern int PLogMPEDump(char *);
339 #else
340 #define PLogEventMPEActivate(a)   0
341 #define PLogEventMPEDeactivate(a) 0
342 #endif
343 
344 #define PLogEventActivate(a)   0
345 #define PLogEventDeactivate(a) 0
346 
347 #define PLogEventActivateClass(a)   0
348 #define PLogEventDeactivateClass(a) 0
349 
350 #define _PLogPLB                        0
351 #define _PLogPLE                        0
352 #define _PLogPHC                        0
353 #define _PLogPHD                        0
354 #define PetscGetFlops()               0.0
355 #define PLogEventBegin(e,o1,o2,o3,o4)
356 #define PLogEventEnd(e,o1,o2,o3,o4)
357 #define PLogObjectParent(p,c)
358 #define PLogObjectParents(p,n,c)
359 #define PLogObjectCreate(h)
360 #define PLogObjectDestroy(h)
361 #define PLogObjectMemory(p,m)
362 #define PLogDestroy()
363 #define PLogStagePush(a)
364 #define PLogStagePop()
365 #define PLogStageRegister(a,b)
366 #define PLogPrintSummary(comm,file)
367 #define PLogBegin()
368 #define PLogTraceBegin(file)            0
369 #define PLogSet(lb,le)
370 #define PLogAllBegin()
371 #define PLogDump(char)
372 #define PLogEventRegister(a,b,c)        0
373 #define PLogMPEBegin()
374 #define PLogMPEDump(a)
375 extern int PLogObjectState(PetscObject,char *,...);
376 
377 /* If PETSC_LOG is NOT defined, these still need to be! */
378 #define MPI_Startall_irecv( count,number,requests) \
379 {                                                  \
380   MPI_Startall( number, requests);                 \
381 }
382 
383 #define MPI_Startall_isend( count,number,requests) \
384 {                                                  \
385   MPI_Startall( number, requests);                 \
386 }
387 
388 #define MPI_Start_isend(count,  requests) \
389 {                                         \
390   MPI_Start( requests);                   \
391 }
392 #endif   /* PETSC_LOG */
393 
394 /*MC
395    PLogFlops - Adds floating point operations to the global counter.
396 
397    Input Parameter:
398 .  f - flop counter
399 
400    Synopsis:
401    void PLogFlops(int f)
402 
403    Notes:
404    A global counter logs all PETSc flop counts.  The user can use
405    PLogFlops() to increment this counter to include flops for the
406    application code.
407 
408    PETSc automatically logs library events if the code has been
409    compiled with -DPETSC_LOG (which is the default), and -log,
410    -log_summary, or -log_all are specified.  PLogFlops() is
411    intended for logging user flops to supplement this PETSc
412    information.
413 
414     Example of Usage:
415 $     int USER_EVENT;
416 $     PLogEventRegister(&USER_EVENT,"User event","Color:");
417 $     PLogEventBegin(USER_EVENT,0,0,0,0);
418 $        [code segment to monitor]
419 $        PLogFlops(user_flops)
420 $     PLogEventEnd(USER_EVENT,0,0,0,0);
421 
422 .seealso: PLogEventRegister(), PLogEventBegin(), PLogEventEnd(), PetscGetFlops()
423 
424 .keywords: log, flops, floating point operations
425 M*/
426 
427 
428 /*MC
429    PLogEventBegin - Logs the beginning of a user event.
430 
431    Input Parameters:
432 .  e - integer associated with the event obtained from PLogEventRegister()
433 .  o1,o2,o3,o4 - objects associated with the event, or 0
434 
435    Synopsis:
436    void PLogEventBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
437                   PetscObject o4)
438 
439    Notes:
440    You should also register each integer event with the command
441    PLogRegisterEvent().  The source code must be compiled with
442    -DPETSC_LOG, which is the default.
443 
444    PETSc automatically logs library events if the code has been
445    compiled with -DPETSC_LOG, and -log, -log_summary, or -log_all are
446    specified.  PLogEventBegin() is intended for logging user events
447    to supplement this PETSc information.
448 
449     Example of Usage:
450 $     int USER_EVENT;
451 $     int user_event_flops;
452 $     PLogEventRegister(&USER_EVENT,"User event","Color:");
453 $     PLogEventBegin(&USER_EVENT,0,0,0,0);
454 $        [code segment to monitor]
455 $        PLogFlops(user_event_flops);
456 $     PLogEventEnd(&USER_EVENT,0,0,0,0);
457 
458 .seealso: PLogEventRegister(), PLogEventEnd(), PLogFlops()
459 
460 .keywords: log, event, begin
461 M*/
462 
463 /*MC
464    PLogEventEnd - Log the end of a user event.
465 
466    Input Parameters:
467 .  e - integer associated with the event obtained with PLogEventRegister()
468 .  o1,o2,o3,o4 - objects associated with the event, or 0
469 
470    Synopsis:
471    void PLogEventEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
472                 PetscObject o4)
473 
474    Notes:
475    You should also register each additional integer event with the command
476    PLogRegisterEvent(). Source code must be compiled with
477    -DPETSC_LOG, which is the default.
478 
479    PETSc automatically logs library events if the code has been
480    compiled with -DPETSC_LOG, and -log, -log_summary, or -log_all are
481    specified.  PLogEventEnd() is intended for logging user events
482    to supplement this PETSc information.
483 
484     Example of Usage:
485 $     int USER_EVENT;
486 $     int user_event_flops;
487 $     PLogEventRegister(&USER_EVENT,"User event","Color:");
488 $     PLogEventBegin(USER_EVENT,0,0,0,0);
489 $        [code segment to monitor]
490 $        PLogFlops(user_event_flops);
491 $     PLogEventEnd(USER_EVENT,0,0,0,0);
492 
493 .seealso: PLogEventRegister(), PLogEventBegin(), PLogFlops()
494 
495 .keywords: log, event, end
496 M*/
497 
498 
499 #endif
500 
501 
502 
503 
504 
505 
506