xref: /petsc/include/petsclog.h (revision ef03ded036f36641663ecc6dce7b752c397a5081)
1 /* $Id: petsclog.h,v 1.145 2000/09/06 20:48:45 bsmith Exp balay $ */
2 
3 /*
4     Defines profile/logging in PETSc.
5 */
6 
7 #if !defined(__PLOG_H)
8 #define __PLOG_H
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/src/plog/src/plog.c,
16   petsc/src/plog/src/plogmpe.c, and
17   petsc/include/finclude/petsclog.h!!!
18 */
19 #define MAT_Mult                                0
20 #define MAT_MatrixFreeMult                      1
21 #define MAT_AssemblyBegin                       2
22 #define MAT_AssemblyEnd                         3
23 #define MAT_GetOrdering                         4
24 #define MAT_MultTranspose                       5
25 #define MAT_MultAdd                             6
26 #define MAT_MultTransposeAdd                    7
27 #define MAT_LUFactor                            8
28 #define MAT_CholeskyFactor                      9
29 #define MAT_LUFactorSymbolic                    10
30 #define MAT_ILUFactorSymbolic                   11
31 #define MAT_CholeskyFactorSymbolic              12
32 #define MAT_IncompleteCholeskyFactorSymbolic    13
33 #define MAT_LUFactorNumeric                     14
34 #define MAT_CholeskyFactorNumeric               15
35 #define MAT_Relax                               16
36 #define MAT_Copy                                17
37 #define MAT_Convert                             18
38 #define MAT_Scale                               19
39 #define MAT_ZeroEntries                         20
40 #define MAT_Solve                               21
41 #define MAT_SolveAdd                            22
42 #define MAT_SolveTranspose                      23
43 #define MAT_SolveTransposeAdd                   24
44 #define MAT_SetValues                           25
45 #define MAT_ForwardSolve                        26
46 #define MAT_BackwardSolve                       27
47 #define MAT_Load                                28
48 #define MAT_View                                29
49 #define MAT_ILUFactor                           30
50 #define MAT_GetColoring                         31
51 #define MAT_GetSubMatrices                      32
52 #define MAT_GetValues                           33
53 #define MAT_IncreaseOverlap                     34
54 #define MAT_GetRow                              35
55 #define MAT_Partitioning                        36
56 
57 #define MAT_FDColoringApply                     38
58 #define MAT_FDColoringCreate                    41
59 
60 #define VEC_ReduceArithmetic                    37
61 
62 #define VEC_View                                39
63 
64 #define VEC_Max                                 42
65 #define VEC_Min                                 43
66 #define VEC_TDot                                44
67 #define VEC_Scale                               45
68 #define VEC_Copy                                46
69 #define VEC_Set                                 47
70 #define VEC_AXPY                                48
71 #define VEC_AYPX                                49
72 #define VEC_Swap                                50
73 #define VEC_WAXPY                               51
74 #define VEC_AssemblyBegin                       52
75 #define VEC_AssemblyEnd                         53
76 #define VEC_MTDot                               54
77 #define VEC_MAXPY                               56
78 #define VEC_PMult                               57
79 #define VEC_SetValues                           58
80 #define VEC_Load                                59
81 #define VEC_ScatterBarrier                      60
82 #define VEC_ScatterBegin                        61
83 #define VEC_ScatterEnd                          62
84 #define VEC_SetRandom                           63
85 
86 #define VEC_NormBarrier                         64
87 #define VEC_Norm                                65
88 #define VEC_DotBarrier                          66
89 #define VEC_Dot                                 67
90 #define VEC_MDotBarrier                         68
91 #define VEC_MDot                                69
92 
93 #define SLES_Solve                              70
94 #define SLES_SetUp                              71
95 
96 #define KSP_GMRESOrthogonalization              72
97 
98 #define PC_ApplyCoarse                          73
99 #define PC_ModifySubMatrices                    74
100 #define PC_SetUp                                75
101 #define PC_SetUpOnBlocks                        76
102 #define PC_Apply                                77
103 #define PC_ApplySymmetricLeft                   78
104 #define PC_ApplySymmetricRight                  79
105 
106 #define SNES_Solve                              80
107 #define SNES_LineSearch                         81
108 #define SNES_FunctionEval                       82
109 #define SNES_JacobianEval                       83
110 #define SNES_MinimizationFunctionEval           84
111 #define SNES_GradientEval                       85
112 #define SNES_HessianEval                        86
113 
114 #define VEC_ReduceBarrier                       87
115 #define VEC_ReduceComm                          88
116 
117 #define TS_Step                                 90
118 #define TS_PseudoComputeTimeStep                91
119 #define TS_FunctionEval                         92
120 #define TS_JacobianEval                         93
121 
122 #define Petsc_Barrier                           100
123 
124 #define EC_SetUp                                105
125 #define EC_Solve                                106
126 
127 /*
128    Event numbers PLOG_USER_EVENT_LOW to PLOG_USER_EVENT_HIGH are reserved
129    for applications.  Make sure that src/plog/src/plog.c defines enough
130    entries in (*name)[] to go up to PLOG_USER_EVENT_HIGH.
131 */
132 #define PLOG_USER_EVENT_LOW_STATIC              120
133 #define PLOG_USER_EVENT_HIGH                    200
134 
135 /* Global flop counter */
136 extern PLogDouble _TotalFlops;
137 
138 /* General logging of information; different from event logging */
139 EXTERN int PLogInfo(void*,const char[],...);
140 EXTERN int PLogInfoDeactivateClass(int);
141 EXTERN int PLogInfoActivateClass(int);
142 extern int PLogPrintInfo;  /* if 1, indicates PLogInfo() is turned on */
143 
144 #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
145 
146 /*
147    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
148 
149    For the complex numbers version, note that
150        1 complex addition = 2 flops
151        1 complex multiplication = 6 flops,
152    where we define 1 flop as that for a double precision scalar.  We roughly approximate
153    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
154    to the assumption that we're counting mostly additions and multiplications -- and
155    roughly the same number of each.  More accurate counting could be done by distinguishing
156    among the various arithmetic operations.
157  */
158 
159 #if defined(PETSC_USE_COMPLEX)
160 #define PLogFlops(n) (_TotalFlops += (4*n),0)
161 #else
162 #define PLogFlops(n) (_TotalFlops += (n),0)
163 #endif
164 
165 #if defined (PETSC_HAVE_MPE)
166 #include "mpe.h"
167 #define MPEBEGIN    1000
168 EXTERN int PLogMPEBegin(void);
169 EXTERN int PLogMPEDump(const char[]);
170 extern int UseMPE,PLogEventMPEFlags[];
171 EXTERN int PLogEventMPEActivate(int);
172 EXTERN int PLogEventMPEDeactivate(int);
173 #else
174 #define PLogEventMPEActivate(a) 0
175 #define PLogEventMPEDeactivate(a) 0
176 #endif
177 
178 EXTERN int PLogEventActivate(int);
179 EXTERN int PLogEventDeactivate(int);
180 
181 EXTERN int PLogEventActivateClass(int);
182 EXTERN int PLogEventDeactivateClass(int);
183 
184 extern PetscTruth PLogEventFlags[];
185 EXTERN int (*_PLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
186 EXTERN int (*_PLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
187 EXTERN int (*_PLogPHC)(PetscObject);
188 EXTERN int (*_PLogPHD)(PetscObject);
189 
190 extern int PLogEventDepth[];
191 
192 #if defined(PETSC_HAVE_MPE)
193 #define PLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
194   0; { \
195     if (_PLogPLB && PLogEventFlags[e]) {                           \
196       PLogEventBegin((e),o1,o2,o3,o4);                                   \
197       if (UseMPE && PLogEventMPEFlags[(e)]) \
198         MPE_Log_event(MPEBEGIN+2*(e),0,""); \
199       MPI_Barrier(cm);                                             \
200       PLogEventEnd((e),o1,o2,o3,o4);                                     \
201       if (UseMPE && PLogEventMPEFlags[(e)]) \
202         MPE_Log_event(MPEBEGIN+2*((e)+1),0,""); \
203     }                                                                \
204     PLogEventBegin(e+1,o1,o2,o3,o4);                                   \
205     if (UseMPE && PLogEventMPEFlags[(e)+1])\
206       MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");\
207   }
208 #define PLogEventBegin(e,o1,o2,o3,o4)  \
209   0; {  \
210    if (_PLogPLB && PLogEventFlags[(e)] && !PLogEventDepth[e]++) {\
211      (*_PLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
212    if (UseMPE && PLogEventMPEFlags[(e)])\
213      MPE_Log_event(MPEBEGIN+2*(e),0,"");\
214   }
215 #else
216 #define PLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
217   0; { \
218     if (_PLogPLB && PLogEventFlags[(e)]) {                           \
219       PLogEventBegin((e),o1,o2,o3,o4);                                   \
220       MPI_Barrier(cm);                                             \
221       PLogEventEnd((e),o1,o2,o3,o4);                                     \
222     }                                                                \
223     PLogEventBegin((e)+1,o1,o2,o3,o4);                                   \
224   }
225 #define PLogEventBegin(e,o1,o2,o3,o4)  \
226   0; {  \
227    if (_PLogPLB && PLogEventFlags[(e)] && !PLogEventDepth[e]++) {\
228      (*_PLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
229   }
230 #endif
231 
232 #if defined(PETSC_HAVE_MPE)
233 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm) \
234    0; {PLogEventEnd(e+1,o1,o2,o3,o4);}
235 #define PLogEventEnd(e,o1,o2,o3,o4) \
236   0; {\
237   if (_PLogPLE && PLogEventFlags[(e)] && !--PLogEventDepth[e]) {\
238     (*_PLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
239   if (UseMPE && PLogEventMPEFlags[(e)])\
240      MPE_Log_event(MPEBEGIN+2*(e)+1,0,"");\
241   }
242 #else
243 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm) \
244    0; {PLogEventEnd(e+1,o1,o2,o3,o4);}
245 #define PLogEventEnd(e,o1,o2,o3,o4) \
246   0; {\
247   if (_PLogPLE && PLogEventFlags[(e)] && !--PLogEventDepth[e]) {\
248     (*_PLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
249   }
250 #endif
251 
252 #define PLogObjectParent(p,c)       if (c) {PetscValidHeader((PetscObject)(c)); \
253                                      PetscValidHeader((PetscObject)(p));\
254                                      ((PetscObject)(c))->parent = (PetscObject)(p);\
255 				     ((PetscObject)(c))->parentid = ((PetscObject)p)->id;}
256 #define PLogObjectParents(p,n,d)    {int _i; for (_i=0; _i<n; _i++) \
257                                     PLogObjectParent(p,(d)[_i]);}
258 #define PLogObjectCreate(h)         {if (_PLogPHC) (*_PLogPHC)((PetscObject)h);}
259 #define PLogObjectDestroy(h)        {if (_PLogPHD) (*_PLogPHD)((PetscObject)h);}
260 #define PLogObjectMemory(p,m)       {PetscValidHeader((PetscObject)p);\
261                                     ((PetscObject)(p))->mem += (m);}
262 EXTERN int  PLogObjectState(PetscObject,const char[],...);
263 EXTERN int  PLogDestroy(void);
264 EXTERN int  PLogStagePush(int);
265 EXTERN int  PLogStagePop(void);
266 EXTERN int  PLogStageRegister(int,const char[]);
267 EXTERN int  PLogStagePrint(int,PetscTruth);
268 EXTERN int  PLogPrintSummary(MPI_Comm,const char[]);
269 EXTERN int  PLogBegin(void);
270 EXTERN int  PLogTraceBegin(FILE *);
271 EXTERN int  PLogAllBegin(void);
272 EXTERN int  PLogSet(int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject),
273                     int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject));
274 EXTERN int  PLogDump(const char[]);
275 EXTERN int  PLogEventRegister(int*,const char[],const char[]);
276 EXTERN int  PetscGetFlops(PLogDouble*);
277 
278 extern PLogDouble irecv_ct,isend_ct,wait_ct,wait_any_ct,recv_ct,send_ct;
279 extern PLogDouble irecv_len,isend_len,recv_len,send_len;
280 extern PLogDouble wait_all_ct,allreduce_ct,sum_of_waits_ct;
281 extern int        PETSC_DUMMY,PETSC_DUMMY_SIZE;
282 
283 /*
284      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
285    uses macros to defined the MPI operations.
286 
287      It does not work correctly from HP-UX because it processes the
288    macros in a way that sometimes it double counts, hence
289    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
290 
291      It does not work with Windows NT because winmpich lacks MPI_Type_size()
292 */
293 #if !defined(USING_MPIUNI) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
294 /*
295    Logging of MPI activities
296 */
297 
298 #define TypeSize(buff,count,type)                                                \
299 (\
300   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PLogDouble) ((count)*PETSC_DUMMY_SIZE)) \
301 )
302 
303 #define MPI_Irecv(buf,count, datatype,source,tag,comm,request)        \
304 (\
305   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),            \
306   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY                            \
307 )
308 
309 #define MPI_Isend(buf,count, datatype,dest,tag,comm,request)          \
310 (\
311   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),              \
312   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY                          \
313 )
314 
315 #define MPI_Startall_irecv(count,number,requests)                                     \
316 (\
317   PETSC_DUMMY = MPI_Startall(number,requests),                                                    \
318   irecv_ct += (PLogDouble)(number),irecv_len += ((PLogDouble) ((count)*sizeof(Scalar))),PETSC_DUMMY \
319 )
320 
321 #define MPI_Startall_isend(count,number,requests)                                    \
322 (\
323   PETSC_DUMMY = MPI_Startall(number,requests),                                                   \
324   isend_ct += (PLogDouble)(number),isend_len += ((PLogDouble) ((count)*sizeof(Scalar))),PETSC_DUMMY \
325 )
326 
327 #define MPI_Start_isend(count, requests)\
328 (\
329   PETSC_DUMMY = MPI_Start(requests),\
330   isend_ct++,isend_len += ((PLogDouble) ((count)*sizeof(Scalar))),PETSC_DUMMY\
331 )
332 
333 #define MPI_Recv(buf,count, datatype,source,tag,comm,status)           \
334 (\
335   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),               \
336   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY                              \
337 )
338 
339 #define MPI_Send(buf,count, datatype,dest,tag,comm)                     \
340 (\
341   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),                         \
342   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY                              \
343 )
344 
345 #define MPI_Wait(request,status) \
346 (\
347   wait_ct++,sum_of_waits_ct++,  \
348   MPI_Wait(request,status)       \
349 )
350 
351 #define MPI_Waitany(a,b,c,d)     \
352 (\
353   wait_any_ct++,sum_of_waits_ct++,\
354   MPI_Waitany(a,b,c,d)           \
355 )
356 
357 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
358 (\
359   wait_all_ct++,sum_of_waits_ct += (PLogDouble) (count),       \
360   MPI_Waitall(count,array_of_requests,array_of_statuses)       \
361 )
362 
363 #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
364 (\
365   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
366 )
367 
368 #else
369 
370 #define MPI_Startall_irecv(count,number,requests) \
371 (\
372   MPI_Startall(number,requests)                 \
373 )
374 
375 #define MPI_Startall_isend(count,number,requests) \
376 (\
377   MPI_Startall(number,requests)                 \
378 )
379 
380 #define MPI_Start_isend(count, requests) \
381 (\
382   MPI_Start(requests)                   \
383 )
384 
385 #endif /* !USING_MPIUNI && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
386 
387 #else  /* ---Logging is turned off --------------------------------------------*/
388 
389 #define PLogFlops(n)
390 
391 /*
392      With logging turned off, then MPE has to be turned off
393 */
394 #define MPEBEGIN                  1000
395 #define PLogMPEBegin()            0
396 #define PLogMPEDump(a)            0
397 #define PLogEventMPEActivate(a)   0
398 #define PLogEventMPEDeactivate(a) 0
399 
400 #define PLogEventActivate(a)   0
401 #define PLogEventDeactivate(a) 0
402 
403 #define PLogEventActivateClass(a)   0
404 #define PLogEventDeactivateClass(a) 0
405 
406 #define _PLogPLB                        0
407 #define _PLogPLE                        0
408 #define _PLogPHC                        0
409 #define _PLogPHD                        0
410 #define PetscGetFlops(a)                (*(a) = 0.0,0)
411 #define PLogEventBegin(e,o1,o2,o3,o4)   0
412 #define PLogEventEnd(e,o1,o2,o3,o4)     0
413 #define PLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
414 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
415 #define PLogObjectParent(p,c)
416 #define PLogObjectParents(p,n,c)
417 #define PLogObjectCreate(h)
418 #define PLogObjectDestroy(h)
419 #define PLogObjectMemory(p,m)
420 #define PLogDestroy()                   0
421 #define PLogStagePush(a)                0
422 #define PLogStagePop()                  0
423 #define PLogStageRegister(a,b)          0
424 #define PLogStagePrint(a,flg)           0
425 #define PLogPrintSummary(comm,file)     0
426 #define PLogBegin()                     0
427 #define PLogTraceBegin(file)            0
428 #define PLogSet(lb,le)                  0
429 #define PLogAllBegin()                  0
430 #define PLogDump(c)                     0
431 #define PLogEventRegister(a,b,c)        0
432 EXTERN int PLogObjectState(PetscObject,const char[],...);
433 
434 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
435 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
436 
437 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
438 
439 #define MPI_Start_isend(count,requests) MPI_Start(requests)
440 
441 #endif   /* PETSC_USE_LOG */
442 
443 extern PetscTruth PetscPreLoadingUsed;
444 
445 #define PreLoadBegin(flag,name) {PetscTruth PreLoading = flag; int PreLoadMax,PreLoadIt,__ierr;\
446                                  __ierr = OptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(__ierr);\
447                                  PreLoadMax = (int)(PreLoading);PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
448                                  for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
449                                    __ierr = PetscBarrier(PETSC_NULL);CHKERRQ(__ierr);\
450                                    __ierr = PLogStagePush(PETSC_DETERMINE);CHKERRQ(__ierr);\
451                                    __ierr = PLogStageRegister(PETSC_DETERMINE,name);CHKERRQ(__ierr);\
452                                    __ierr = PLogStagePrint(PETSC_DETERMINE,(PetscTruth)(!PreLoadMax || PreLoadIt));
453 #define PreLoadEnd()               __ierr = PLogStagePop();CHKERRQ(__ierr);PreLoading = PETSC_FALSE;}}
454 #define PreLoadStage(name)         __ierr = PLogStagePop();CHKERRQ(__ierr);\
455                                    __ierr = PLogStagePush(PETSC_DETERMINE);CHKERRQ(__ierr);\
456                                    __ierr = PLogStageRegister(PETSC_DETERMINE,name);CHKERRQ(__ierr);\
457                                    __ierr = PLogStagePrint(PETSC_DETERMINE,(PetscTruth)(!PreLoadMax || PreLoadIt));
458 #endif
459 
460 
461 
462 
463 
464 
465