xref: /petsc/include/petsclog.h (revision 29bbc08cd5461c366aba6645924e8ff42acd1de0)
1 /* $Id: petsclog.h,v 1.146 2000/09/06 22:20:52 balay 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; { int __ierr; \
195     if (_PLogPLB && PLogEventFlags[e]) {                         \
196       __ierr = PLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(__ierr);  \
197       if (UseMPE && PLogEventMPEFlags[(e)])                      \
198         MPE_Log_event(MPEBEGIN+2*(e),0,"");                      \
199       __ierr = MPI_Barrier(cm);CHKERRQ(__ierr);                  \
200       __ierr = PLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(__ierr);    \
201       if (UseMPE && PLogEventMPEFlags[(e)])                      \
202         MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                  \
203     }                                                            \
204     __ierr = PLogEventBegin(e+1,o1,o2,o3,o4);CHKERRQ(__ierr);    \
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; { int __ierr;\
218     if (_PLogPLB && PLogEventFlags[(e)]) {                         \
219       __ierr = PLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(__ierr);    \
220       __ierr = MPI_Barrier(cm);CHKERRQ(__ierr);                    \
221       __ierr = PLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(__ierr);      \
222     }                                                              \
223     __ierr = PLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(__ierr);    \
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) PLogEventEnd(e+1,o1,o2,o3,o4)
234 #define PLogEventEnd(e,o1,o2,o3,o4) \
235   0; {\
236   if (_PLogPLE && PLogEventFlags[(e)] && !--PLogEventDepth[e]) {\
237     (*_PLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
238   if (UseMPE && PLogEventMPEFlags[(e)])\
239      MPE_Log_event(MPEBEGIN+2*(e)+1,0,"");\
240   }
241 #else
242 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PLogEventEnd(e+1,o1,o2,o3,o4)
243 #define PLogEventEnd(e,o1,o2,o3,o4) \
244   0; {\
245   if (_PLogPLE && PLogEventFlags[(e)] && !--PLogEventDepth[e]) {\
246     (*_PLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
247   }
248 #endif
249 
250 #define PLogObjectParent(p,c)       if (c) {PetscValidHeader((PetscObject)(c)); \
251                                      PetscValidHeader((PetscObject)(p));\
252                                      ((PetscObject)(c))->parent = (PetscObject)(p);\
253 				     ((PetscObject)(c))->parentid = ((PetscObject)p)->id;}
254 #define PLogObjectParents(p,n,d)    {int _i; for (_i=0; _i<n; _i++) \
255                                     PLogObjectParent(p,(d)[_i]);}
256 #define PLogObjectCreate(h)         {if (_PLogPHC) (*_PLogPHC)((PetscObject)h);}
257 #define PLogObjectDestroy(h)        {if (_PLogPHD) (*_PLogPHD)((PetscObject)h);}
258 #define PLogObjectMemory(p,m)       {PetscValidHeader((PetscObject)p);\
259                                     ((PetscObject)(p))->mem += (m);}
260 EXTERN int  PLogObjectState(PetscObject,const char[],...);
261 EXTERN int  PLogDestroy(void);
262 EXTERN int  PLogStagePush(int);
263 EXTERN int  PLogStagePop(void);
264 EXTERN int  PLogStageRegister(int,const char[]);
265 EXTERN int  PLogStagePrint(int,PetscTruth);
266 EXTERN int  PLogPrintSummary(MPI_Comm,const char[]);
267 EXTERN int  PLogBegin(void);
268 EXTERN int  PLogTraceBegin(FILE *);
269 EXTERN int  PLogAllBegin(void);
270 EXTERN int  PLogSet(int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject),
271                     int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject));
272 EXTERN int  PLogDump(const char[]);
273 EXTERN int  PLogEventRegister(int*,const char[],const char[]);
274 EXTERN int  PetscGetFlops(PLogDouble*);
275 
276 extern PLogDouble irecv_ct,isend_ct,wait_ct,wait_any_ct,recv_ct,send_ct;
277 extern PLogDouble irecv_len,isend_len,recv_len,send_len;
278 extern PLogDouble wait_all_ct,allreduce_ct,sum_of_waits_ct;
279 extern int        PETSC_DUMMY,PETSC_DUMMY_SIZE;
280 
281 /*
282      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
283    uses macros to defined the MPI operations.
284 
285      It does not work correctly from HP-UX because it processes the
286    macros in a way that sometimes it double counts, hence
287    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
288 
289      It does not work with Windows NT because winmpich lacks MPI_Type_size()
290 */
291 #if !defined(USING_MPIUNI) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
292 /*
293    Logging of MPI activities
294 */
295 
296 #define TypeSize(buff,count,type)                                                \
297 (\
298   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PLogDouble) ((count)*PETSC_DUMMY_SIZE)) \
299 )
300 
301 #define MPI_Irecv(buf,count, datatype,source,tag,comm,request)        \
302 (\
303   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),            \
304   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY                            \
305 )
306 
307 #define MPI_Isend(buf,count, datatype,dest,tag,comm,request)          \
308 (\
309   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),              \
310   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY                          \
311 )
312 
313 #define MPI_Startall_irecv(count,number,requests)                                     \
314 (\
315   PETSC_DUMMY = MPI_Startall(number,requests),                                                    \
316   irecv_ct += (PLogDouble)(number),irecv_len += ((PLogDouble) ((count)*sizeof(Scalar))),PETSC_DUMMY \
317 )
318 
319 #define MPI_Startall_isend(count,number,requests)                                    \
320 (\
321   PETSC_DUMMY = MPI_Startall(number,requests),                                                   \
322   isend_ct += (PLogDouble)(number),isend_len += ((PLogDouble) ((count)*sizeof(Scalar))),PETSC_DUMMY \
323 )
324 
325 #define MPI_Start_isend(count, requests)\
326 (\
327   PETSC_DUMMY = MPI_Start(requests),\
328   isend_ct++,isend_len += ((PLogDouble) ((count)*sizeof(Scalar))),PETSC_DUMMY\
329 )
330 
331 #define MPI_Recv(buf,count, datatype,source,tag,comm,status)           \
332 (\
333   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),               \
334   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY                              \
335 )
336 
337 #define MPI_Send(buf,count, datatype,dest,tag,comm)                     \
338 (\
339   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),                         \
340   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY                              \
341 )
342 
343 #define MPI_Wait(request,status) \
344 (\
345   wait_ct++,sum_of_waits_ct++,  \
346   MPI_Wait(request,status)       \
347 )
348 
349 #define MPI_Waitany(a,b,c,d)     \
350 (\
351   wait_any_ct++,sum_of_waits_ct++,\
352   MPI_Waitany(a,b,c,d)           \
353 )
354 
355 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
356 (\
357   wait_all_ct++,sum_of_waits_ct += (PLogDouble) (count),       \
358   MPI_Waitall(count,array_of_requests,array_of_statuses)       \
359 )
360 
361 #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
362 (\
363   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
364 )
365 
366 #else
367 
368 #define MPI_Startall_irecv(count,number,requests) \
369 (\
370   MPI_Startall(number,requests)                 \
371 )
372 
373 #define MPI_Startall_isend(count,number,requests) \
374 (\
375   MPI_Startall(number,requests)                 \
376 )
377 
378 #define MPI_Start_isend(count, requests) \
379 (\
380   MPI_Start(requests)                   \
381 )
382 
383 #endif /* !USING_MPIUNI && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
384 
385 #else  /* ---Logging is turned off --------------------------------------------*/
386 
387 #define PLogFlops(n)
388 
389 /*
390      With logging turned off, then MPE has to be turned off
391 */
392 #define MPEBEGIN                  1000
393 #define PLogMPEBegin()            0
394 #define PLogMPEDump(a)            0
395 #define PLogEventMPEActivate(a)   0
396 #define PLogEventMPEDeactivate(a) 0
397 
398 #define PLogEventActivate(a)   0
399 #define PLogEventDeactivate(a) 0
400 
401 #define PLogEventActivateClass(a)   0
402 #define PLogEventDeactivateClass(a) 0
403 
404 #define _PLogPLB                        0
405 #define _PLogPLE                        0
406 #define _PLogPHC                        0
407 #define _PLogPHD                        0
408 #define PetscGetFlops(a)                (*(a) = 0.0,0)
409 #define PLogEventBegin(e,o1,o2,o3,o4)   0
410 #define PLogEventEnd(e,o1,o2,o3,o4)     0
411 #define PLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
412 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
413 #define PLogObjectParent(p,c)
414 #define PLogObjectParents(p,n,c)
415 #define PLogObjectCreate(h)
416 #define PLogObjectDestroy(h)
417 #define PLogObjectMemory(p,m)
418 #define PLogDestroy()                   0
419 #define PLogStagePush(a)                0
420 #define PLogStagePop()                  0
421 #define PLogStageRegister(a,b)          0
422 #define PLogStagePrint(a,flg)           0
423 #define PLogPrintSummary(comm,file)     0
424 #define PLogBegin()                     0
425 #define PLogTraceBegin(file)            0
426 #define PLogSet(lb,le)                  0
427 #define PLogAllBegin()                  0
428 #define PLogDump(c)                     0
429 #define PLogEventRegister(a,b,c)        0
430 EXTERN int PLogObjectState(PetscObject,const char[],...);
431 
432 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
433 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
434 
435 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
436 
437 #define MPI_Start_isend(count,requests) MPI_Start(requests)
438 
439 #endif   /* PETSC_USE_LOG */
440 
441 extern PetscTruth PetscPreLoadingUsed;
442 
443 #define PreLoadBegin(flag,name) {PetscTruth PreLoading = flag; int PreLoadMax,PreLoadIt,__ierr;\
444                                  __ierr = OptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(__ierr);\
445                                  PreLoadMax = (int)(PreLoading);PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
446                                  for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
447                                    __ierr = PetscBarrier(PETSC_NULL);CHKERRQ(__ierr);\
448                                    __ierr = PLogStagePush(PETSC_DETERMINE);CHKERRQ(__ierr);\
449                                    __ierr = PLogStageRegister(PETSC_DETERMINE,name);CHKERRQ(__ierr);\
450                                    __ierr = PLogStagePrint(PETSC_DETERMINE,(PetscTruth)(!PreLoadMax || PreLoadIt));
451 #define PreLoadEnd()               __ierr = PLogStagePop();CHKERRQ(__ierr);PreLoading = PETSC_FALSE;}}
452 #define PreLoadStage(name)         __ierr = PLogStagePop();CHKERRQ(__ierr);\
453                                    __ierr = PLogStagePush(PETSC_DETERMINE);CHKERRQ(__ierr);\
454                                    __ierr = PLogStageRegister(PETSC_DETERMINE,name);CHKERRQ(__ierr);\
455                                    __ierr = PLogStagePrint(PETSC_DETERMINE,(PetscTruth)(!PreLoadMax || PreLoadIt));
456 #endif
457 
458 
459 
460 
461 
462 
463