xref: /petsc/include/petsclog.h (revision a7a1495cff6e7d7f13bcb4a602de4e22c1c115f6)
1 /* $Id: petsclog.h,v 1.137 2000/02/24 22:23:48 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 VEC_ReduceArithmetic                    37
58 #define VEC_ReduceCommunication                 38
59 #define VEC_ScatterBarrier                      39
60 #define VEC_ScatterCommunication                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 VEC_NormBarrier                         64
86 #define VEC_NormComm                            65
87 #define VEC_DotBarrier                          66
88 #define VEC_DotComm                             67
89 #define VEC_MDotBarrier                         68
90 #define VEC_MDotComm                            69
91 
92 #define SLES_Solve                              70
93 #define SLES_SetUp                              71
94 
95 #define KSP_GMRESOrthogonalization              72
96 
97 #define PC_ModifySubMatrices                    74
98 #define PC_SetUp                                75
99 #define PC_SetUpOnBlocks                        76
100 #define PC_Apply                                77
101 #define PC_ApplySymmetricLeft                   78
102 #define PC_ApplySymmetricRight                  79
103 
104 #define SNES_Solve                              80
105 #define SNES_LineSearch                         81
106 #define SNES_FunctionEval                       82
107 #define SNES_JacobianEval                       83
108 #define SNES_MinimizationFunctionEval           84
109 #define SNES_GradientEval                       85
110 #define SNES_HessianEval                        86
111 
112 #define VEC_ReduceBarrier                       87
113 #define VEC_ReduceCommOnly                      88
114 #define VEC_Dot                                 89
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 PetscTruth 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       PLogEventDepth[e] = PETSC_TRUE;  \
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   { \
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   {  \
227    if (_PLogPLB && PLogEventFlags[(e)] && !PLogEventDepth[e]) {\
228       PLogEventDepth[e] = PETSC_TRUE;  \
229      (*_PLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
230   }
231 #endif
232 
233 #if defined(PETSC_HAVE_MPE)
234 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm) {\
235   if (_PLogPLE && PLogEventFlags[(e)+1]) \
236     (*_PLogPLE)((e)+1,0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
237   if (UseMPE && PLogEventMPEFlags[(e)+1])\
238      MPE_Log_event(MPEBEGIN+2*((e)+1)+1,0,"");\
239   }
240 #define PLogEventEnd(e,o1,o2,o3,o4) {\
241   if (_PLogPLE && PLogEventFlags[(e)]) {\
242     (*_PLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
243     PLogEventDepth[e] = PETSC_FALSE;  }\
244   if (UseMPE && PLogEventMPEFlags[(e)])\
245      MPE_Log_event(MPEBEGIN+2*(e)+1,0,"");\
246   }
247 #else
248 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm) {\
249   if (_PLogPLE && PLogEventFlags[(e)+1]) {\
250     (*_PLogPLE)((e)+1,0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));} \
251   }
252 #define PLogEventEnd(e,o1,o2,o3,o4) {\
253   if (_PLogPLE && PLogEventFlags[(e)]) {\
254     (*_PLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
255     PLogEventDepth[e] = PETSC_FALSE;  }\
256   }
257 #endif
258 
259 #define PLogObjectParent(p,c)       if (c) {PetscValidHeader((PetscObject)(c)); \
260                                      PetscValidHeader((PetscObject)(p));\
261                                      ((PetscObject)(c))->parent = (PetscObject)(p);\
262 				     ((PetscObject)(c))->parentid = ((PetscObject)p)->id;}
263 #define PLogObjectParents(p,n,d)    {int _i; for (_i=0; _i<n; _i++) \
264                                     PLogObjectParent(p,(d)[_i]);}
265 #define PLogObjectCreate(h)         {if (_PLogPHC) (*_PLogPHC)((PetscObject)h);}
266 #define PLogObjectDestroy(h)        {if (_PLogPHD) (*_PLogPHD)((PetscObject)h);}
267 #define PLogObjectMemory(p,m)       {PetscValidHeader((PetscObject)p);\
268                                     ((PetscObject)(p))->mem += (m);}
269 extern int  PLogObjectState(PetscObject,const char[],...);
270 extern int  PLogDestroy(void);
271 extern int  PLogStagePush(int);
272 extern int  PLogStagePop(void);
273 extern int  PLogStageRegister(int,const char[]);
274 extern int  PLogPrintSummary(MPI_Comm,const char[]);
275 extern int  PLogBegin(void);
276 extern int  PLogTraceBegin(FILE *);
277 extern int  PLogAllBegin(void);
278 extern int  PLogSet(int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject),
279                     int (*)(int,int,PetscObject,PetscObject,PetscObject,PetscObject));
280 extern int  PLogDump(const char[]);
281 extern int  PLogEventRegister(int*,const char[],const char[]);
282 extern int  PetscGetFlops(PLogDouble*);
283 
284 extern PLogDouble irecv_ct,isend_ct,wait_ct,wait_any_ct,recv_ct,send_ct;
285 extern PLogDouble irecv_len,isend_len,recv_len,send_len;
286 extern PLogDouble wait_all_ct,allreduce_ct,sum_of_waits_ct;
287 extern int        PETSC_DUMMY,PETSC_DUMMY_SIZE;
288 
289 /*
290      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
291    uses macros to defined the MPI operations.
292 
293      It does not work correctly from HP-UX because it processes the
294    macros in a way that sometimes it double counts, hence
295    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
296 
297      It does not work with Windows NT because winmpich lacks MPI_Type_size()
298 */
299 #if !defined(USING_MPIUNI) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
300 /*
301    Logging of MPI activities
302 */
303 
304 #define TypeSize(buff,count,type)                                                \
305 (\
306   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PLogDouble) ((count)*PETSC_DUMMY_SIZE)) \
307 )
308 
309 #define MPI_Irecv(buf,count, datatype,source,tag,comm,request)        \
310 (\
311   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),            \
312   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY                            \
313 )
314 
315 #define MPI_Isend(buf,count, datatype,dest,tag,comm,request)          \
316 (\
317   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),              \
318   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY                          \
319 )
320 
321 #define MPI_Startall_irecv(count,number,requests)                                     \
322 (\
323   PETSC_DUMMY = MPI_Startall(number,requests),                                                    \
324   irecv_ct += (PLogDouble)(number),irecv_len += ((PLogDouble) (count*sizeof(Scalar))),PETSC_DUMMY \
325 )
326 
327 #define MPI_Startall_isend(count,number,requests)                                    \
328 (\
329   PETSC_DUMMY = MPI_Startall(number,requests),                                                   \
330   isend_ct += (PLogDouble)(number),isend_len += ((PLogDouble) (count*sizeof(Scalar))),PETSC_DUMMY \
331 )
332 
333 #define MPI_Start_isend(count, requests)\
334 (\
335   PETSC_DUMMY = MPI_Start(requests),\
336   isend_ct++,isend_len += ((PLogDouble) (count*sizeof(Scalar))),PETSC_DUMMY\
337 )
338 
339 #define MPI_Recv(buf,count, datatype,source,tag,comm,status)           \
340 (\
341   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),               \
342   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY                              \
343 )
344 
345 #define MPI_Send(buf,count, datatype,dest,tag,comm)                     \
346 (\
347   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),                         \
348   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY                              \
349 )
350 
351 #define MPI_Wait(request,status) \
352 (\
353   wait_ct++,sum_of_waits_ct++,  \
354   MPI_Wait(request,status)       \
355 )
356 
357 #define MPI_Waitany(a,b,c,d)     \
358 (\
359   wait_any_ct++,sum_of_waits_ct++,\
360   MPI_Waitany(a,b,c,d)           \
361 )
362 
363 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
364 (\
365   wait_all_ct++,sum_of_waits_ct += (PLogDouble) (count),       \
366   MPI_Waitall(count,array_of_requests,array_of_statuses)       \
367 )
368 
369 #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
370 (\
371   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
372 )
373 
374 #else
375 
376 #define MPI_Startall_irecv(count,number,requests) \
377 (\
378   MPI_Startall(number,requests)                 \
379 )
380 
381 #define MPI_Startall_isend(count,number,requests) \
382 (\
383   MPI_Startall(number,requests)                 \
384 )
385 
386 #define MPI_Start_isend(count, requests) \
387 (\
388   MPI_Start(requests)                   \
389 )
390 
391 #endif /* !USING_MPIUNI && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
392 
393 #else  /* ---Logging is turned off --------------------------------------------*/
394 
395 #define PLogFlops(n)
396 
397 /*
398      With logging turned off, then MPE has to be turned off
399 */
400 #define MPEBEGIN                  1000
401 #define PLogMPEBegin()
402 #define PLogMPEDump(a)            0
403 #define PLogEventMPEActivate(a)   0
404 #define PLogEventMPEDeactivate(a) 0
405 
406 #define PLogEventActivate(a)   0
407 #define PLogEventDeactivate(a) 0
408 
409 #define PLogEventActivateClass(a)   0
410 #define PLogEventDeactivateClass(a) 0
411 
412 #define _PLogPLB                        0
413 #define _PLogPLE                        0
414 #define _PLogPHC                        0
415 #define _PLogPHD                        0
416 #define PetscGetFlops(a)                (*(a) = 0.0,0)
417 #define PLogEventBegin(e,o1,o2,o3,o4)
418 #define PLogEventEnd(e,o1,o2,o3,o4)
419 #define PLogEventBarrierBegin(e,o1,o2,o3,o4,cm)
420 #define PLogEventBarrierEnd(e,o1,o2,o3,o4,cm)
421 #define PLogObjectParent(p,c)
422 #define PLogObjectParents(p,n,c)
423 #define PLogObjectCreate(h)
424 #define PLogObjectDestroy(h)
425 #define PLogObjectMemory(p,m)
426 #define PLogDestroy()                   0
427 #define PLogStagePush(a)                0
428 #define PLogStagePop()                  0
429 #define PLogStageRegister(a,b)          0
430 #define PLogPrintSummary(comm,file)     0
431 #define PLogBegin()                     0
432 #define PLogTraceBegin(file)            0
433 #define PLogSet(lb,le)                  0
434 #define PLogAllBegin()                  0
435 #define PLogDump(c)                     0
436 #define PLogEventRegister(a,b,c)        0
437 extern int PLogObjectState(PetscObject,const char[],...);
438 
439 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
440 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
441 
442 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
443 
444 #define MPI_Start_isend(count,requests) MPI_Start(requests)
445 
446 #endif   /* PETSC_USE_LOG */
447 
448 
449 #endif
450 
451 
452 
453 
454 
455 
456