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