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