Actual source code: plog.c
1: /*$Id: plog.c,v 1.259 2001/04/10 22:34:32 balay Exp $*/
2: /*
3: PETSc code to log object creation and destruction and PETSc events.
4: */
5: #include "petsc.h" /*I "petsc.h" I*/
6: #include "petscts.h" /* This include is to define all the PETSc cookies */
7: #include "petscmachineinfo.h"
8: #if defined(PETSC_HAVE_MPE)
9: #include "mpe.h"
10: #endif
11: #include <stdarg.h>
12: #include <sys/types.h>
13: #include "petscsys.h"
14: #if defined(PETSC_HAVE_STDLIB_H)
15: #include <stdlib.h>
16: #endif
17: #if defined(PETSC_HAVE_MALLOC_H) && !defined(__cplusplus)
18: #include <malloc.h>
19: #endif
20: #include "petscfix.h"
21: #include "src/sys/src/plog/ptime.h"
23: /*
24: The next three variables determine which, if any, PetscLogInfo() calls are used.
25: If PetscLogPrintInfo is false, no info messages are printed.
26: IF PetscLogPrintInfoNull is false, no info messages associated with a null object are printed.
28: If PetscLogInfoFlags[OBJECT_COOKIE - PETSC_COOKIE] is zero, no messages related
29: to that object are printed. OBJECT_COOKIE is, for example, MAT_COOKIE.
30: */
31: PetscTruth PetscLogPrintInfo = PETSC_FALSE,PetscLogPrintInfoNull = PETSC_FALSE;
32: int PetscLogInfoFlags[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
33: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
34: 1,1,1,1,1,1,1,1,1,1,1,1};
35: FILE *PetscLogInfoFile;
37: /*@C
38: PetscLogInfoAllow - Causes PetscLogInfo() messages to be printed to standard output.
40: Not Collective, each processor may call this seperately, but printing is only
41: turned on if the lowest processor number associated with the PetscObject associated
42: with the call to PetscLogInfo() has called this routine.
44: Input Parameter:
45: + flag - PETSC_TRUE or PETSC_FALSE
46: - filename - optional name of file to write output to (defaults to stdout)
48: Options Database Key:
49: . -log_info - Activates PetscLogInfoAllow()
51: Level: advanced
53: Concepts: debugging^detailed runtime information
54: Concepts: dumping detailed runtime information
56: .seealso: PetscLogInfo()
57: @*/
58: int PetscLogInfoAllow(PetscTruth flag,char *filename)
59: {
60: char fname[256],tname[5];
61: int ierr,rank;
64: PetscLogPrintInfo = flag;
65: PetscLogPrintInfoNull = flag;
66: if (flag && filename) {
67: PetscFixFilename(filename,fname);
68: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
69: sprintf(tname,".%d",rank);
70: PetscStrcat(fname,tname);
71: PetscLogInfoFile = fopen(fname,"w");
72: if (!PetscLogInfoFile) SETERRQ1(1,"Cannot open requested file for writing: %s",fname);
73: } else if (flag) {
74: PetscLogInfoFile = stdout;
75: }
76: return(0);
77: }
79: /*@
80: PetscLogInfoDeactivateClass - Deactivates PetscLogInfo() messages for a PETSc object class.
82: Not Collective
84: Input Parameter:
85: . objclass - object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
87: Notes:
88: One can pass PETSC_NULL to deactive all messages that are not associated
89: with an object.
91: Level: developer
93: .seealso: PetscLogInfoActivateClass(), PetscLogInfo(), PetscLogInfoAllow()
94: @*/
95: int PetscLogInfoDeactivateClass(int objclass)
96: {
98:
99: if (!objclass) {
100: PetscLogPrintInfoNull = PETSC_FALSE;
101: return(0);
102: }
103: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 0;
104:
105: if (objclass == SLES_COOKIE) {
106: PetscLogInfoFlags[PC_COOKIE - PETSC_COOKIE - 1] = 0;
107: PetscLogInfoFlags[KSP_COOKIE - PETSC_COOKIE - 1] = 0;
108: }
109: return(0);
110: }
112: /*@
113: PetscLogInfoActivateClass - Activates PetscLogInfo() messages for a PETSc
114: object class.
116: Not Collective
118: Input Parameter:
119: . objclass - object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.
121: Level: developer
123: .seealso: PetscLogInfoDeactivateClass(), PetscLogInfo(), PetscLogInfoAllow()
124: @*/
125: int PetscLogInfoActivateClass(int objclass)
126: {
128: if (!objclass) {
129: PetscLogPrintInfoNull = PETSC_FALSE;
130: } else {
131: PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 1;
132: if (objclass == SLES_COOKIE) {
133: PetscLogInfoFlags[PC_COOKIE - PETSC_COOKIE - 1] = 1;
134: PetscLogInfoFlags[KSP_COOKIE - PETSC_COOKIE - 1] = 1;
135: }
136: }
137: return(0);
138: }
141: /* -------------------------------------------------------------------*/
142: #if defined(PETSC_USE_LOG)
143: static int PETSC_LOG_USER_EVENT_LOW = PETSC_LOG_USER_EVENT_LOW_STATIC;
145: /*
146: Make sure that all events used by PETSc have the
147: corresponding flags set here:
148: 1 - activated for PETSc logging
149: 0 - not activated for PETSc logging
150: */
151: int PetscLogEventDepth[200];
152: PetscTruth PetscLogEventFlags[] = {PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 0 - 24*/
153: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
154: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
155: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
156: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
157: PETSC_FALSE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 25 -49 */
158: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
159: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_FALSE,
160: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
161: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
162: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 50 - 74 */
163: PETSC_FALSE,PETSC_TRUE,PETSC_TRUE,PETSC_FALSE,PETSC_TRUE,
164: PETSC_FALSE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_FALSE,
165: PETSC_TRUE,PETSC_FALSE,PETSC_TRUE,PETSC_FALSE,PETSC_TRUE,
166: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
167: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 75 - 99 */
168: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
169: PETSC_TRUE,PETSC_TRUE,PETSC_FALSE,PETSC_TRUE,PETSC_TRUE,
170: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
171: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
172: PETSC_TRUE,PETSC_FALSE,PETSC_FALSE,PETSC_TRUE,PETSC_TRUE, /* 100 - 124 */
173: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
174: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
175: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
176: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
177: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 125 - 149 */
178: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
179: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
180: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
181: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
182: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 150 - 174 */
183: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
184: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
185: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
186: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
187: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
188: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE, /* 175 - 199 */
189: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
190: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
191: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
192: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE};
194: static char *(oname[]) = {"Viewer ",
195: "Index set ",
196: "Vector ",
197: "Vector Scatter ",
198: "Matrix ",
199: "Draw ",
200: "Line graph ",
201: "Krylov Solver ",
202: "Preconditioner ",
203: "SLES ", /* 10 */
204: "EC ", /* 11 */
205: " ",
206: "SNES ",
207: "Distributed array",
208: "DF ", /* 15 */
209: "Axis ", /* 16 */
210: "Null Space ",
211: "TS ",
212: "Random ",
213: "AO ", /* 20 */
214: "DC ",
215: "FD Coloring ",
216: "Grid ", /* 23 */
217: " ",
218: " ",
219: " ",
220: "Draw SP ", /* 27 */
221: " ",
222: " ",
223: " ",
224: " ",
225: " ",
226: " ",
227: " ",
228: " ",
229: " ",
230: " ",
231: " ",
232: " ",
233: " ",
234: " ",
235: " ",
236: " ",
237: " ",
238: " ",
239: " ",
240: " ",
241: " ",
242: " ",
243: " "};
245: char *(PetscLogEventName[]) = {"MatMult ",
246: "MatMatFreeMult ",
247: "MatAssemblyBegin",
248: "MatAssemblyEnd ",
249: "MatGetOrdering ",
250: "MatMultTranspose",
251: "MatMultAdd ",
252: "MatMultTransAdd ",
253: "MatLUFactor ",
254: "MatCholeskyFctr ",
255: "MatLUFctrSymbol ",
256: "MatILUFctrSymbol",
257: "MatCholeskyFctr ",
258: "MatIncompleteCho",
259: "MatLUFactorNumer",
260: "MatCholeskyFact ",
261: "MatRelax ",
262: "MatCopy ",
263: "MatConvert ",
264: "MatScale ",
265: "MatZeroEntries ",
266: "MatSolve ",
267: "MatSolveAdd ",
268: "MatSolveTranspos",
269: "MatSolveTransAdd",
270: "MatSetValues ",
271: "MatForwardSolve ",
272: "MatBackwardSolve",
273: "MatLoad ",
274: "MatView ",
275: "MatILUFactor ",
276: "MatGetColoring ",
277: "MatGetSubMatrice",
278: "MatGetValues ",
279: "MatIncreaseOvlap",
280: "MatGetRow ",
281: "MatGetPartitioni",
282: "VecReduceArith. ",
283: "MatFDColoringApp",
284: "VecView ",
285: " ",
286: "MatFDColoringCre",
287: "VecMax ",
288: "VecMin ",
289: "VecTDot ",
290: "VecScale ",
291: "VecCopy ",
292: "VecSet ",
293: "VecAXPY ",
294: "VecAYPX ",
295: "VecSwap ",
296: "VecWAXPY ",
297: "VecAssemblyBegin",
298: "VecAssemblyEnd ",
299: "VecMTDot ",
300: " ",
301: "VecMAXPY ",
302: "VecPointwiseMult",
303: "VecSetValues ",
304: "VecLoad ",
305: "VecScatterBarrie",
306: "VecScatterBegin ",
307: "VecScatterEnd ",
308: "VecSetRandom ",
309: "VecNormBarrier ",
310: "VecNorm ",
311: "VecDotBarrier ",
312: "VecDot ",
313: "VecMDotBarrier ",
314: "VecMDot ",
315: "SLESSolve ",
316: "SLESSetUp ",
317: "KSPGMRESOrthog ",
318: "PCApplyCoarse ",
319: "PCModifySubMat ",
320: "PCSetUp ",
321: "PCSetUpOnBlocks ",
322: "PCApply ",
323: "PCApplySymmLeft ",
324: "PCApplySymmRight",
325: "SNESSolve ",
326: "SNESLineSearch ",
327: "SNESFunctionEval",
328: "SNESJacobianEval",
329: "SNESMinFunctnEvl",
330: "SNESGradientEval",
331: "SNESHessianEval ",
332: "VecReduceBarrier",
333: "VecReduceCommuni",
334: " ",
335: "TSStep ",
336: "TSPseudoCmptTStp",
337: "TSFunctionEval ",
338: "TSJacobianEval ",
339: " ",
340: " ",
341: " ",
342: " ",
343: " ",
344: " ",
345: "PetscBarrier ", /* 100 */
346: " ",
347: " ",
348: " ",
349: " ",
350: "ECSetUp ",
351: "ECSolve ",
352: " ",
353: " ",
354: " ",
355: " ",
356: " ",
357: " ",
358: " ",
359: " "," "," "," "," ",
360: " "," "," "," "," ",
361: " "," "," "," "," ",
362: " "," "," "," "," ",
363: " "," "," "," "," ",
364: " "," "," "," "," ",
365: " "," "," "," "," ",
366: " "," "," "," "," ",
367: " "," "," "," "," ",
368: " "," "," "," "," ",
369: " "," "," "," "," ",
370: " "," "," "," "," ",
371: " "," "," "," "," ",
372: " "," "," "," "," ",
373: " "," "," "," "," ",
374: " "," "," "," "," ",
375: " "," "," "," "," ",
376: " "," "," "," "," ",
377: " "," "," "," "," ",
378: " "," "," "," "," "};
380: #define CHUNCK 1000
381: #define CREATE 0
382: #define DESTROY 1
383: #define ACTIONBEGIN 2
384: #define ACTIONEND 3
386: /*
387: flops contains cumulative flops
388: mem contains current memory usage
389: memmax contains maximum memory usage so far
390: */
391: typedef struct {
392: PetscLogDouble time,flops,mem,maxmem;
393: int cookie,type,event,id1,id2,id3;
394: } Events;
396: typedef struct {
397: int parent;
398: PetscLogDouble mem;
399: char string[64];
400: char name[32];
401: PetscObject obj;
402: } Objects;
404: /*
405: Global counters
406: */
407: PetscLogDouble _TotalFlops = 0.0;
408: PetscLogDouble irecv_ct = 0.0,isend_ct = 0.0,wait_ct = 0.0,wait_any_ct = 0.0;
409: PetscLogDouble irecv_len = 0.0,isend_len = 0.0,recv_len = 0.0,send_len = 0.0;
410: PetscLogDouble send_ct = 0.0,recv_ct = 0.0;
411: PetscLogDouble wait_all_ct = 0.0,allreduce_ct = 0.0,sum_of_waits_ct = 0.0;
413: /* used in the MPI_XXX() count macros in petsclog.h */
414: int PETSC_DUMMY,PETSC_DUMMY_SIZE;
416: /*
417: Log counters in this file only
418: */
419: static PetscLogDouble BaseTime;
420: static Events *events = 0;
421: static Objects *objects = 0;
423: static int nobjects = 0,nevents = 0,objectsspace = CHUNCK;
424: static int ObjectsDestroyed = 0,eventsspace = CHUNCK;
425: static PetscLogDouble ObjectsType[10][PETSC_MAX_COOKIES][4];
427: static int EventsStage = 0; /* which log sessions are we using */
428: static int EventsStageMax = 0; /* highest event log used */
429: static int EventsStagePushed = 0;
430: static int EventsStageStack[100];
431: static char *(EventsStageName[]) = {0,0,0,0,0,0,0,0,0,0};
432: static PetscLogDouble EventsStageFlops[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
433: static PetscLogDouble EventsStageTime[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
434: static PetscLogDouble EventsStageMessageCounts[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
435: static PetscLogDouble EventsStageMessageLengths[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
436: static PetscLogDouble EventsStageReductions[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
437: PetscTruth PetscLogStagePrintFlag[] = {PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,
438: PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE,PETSC_TRUE};
439: #define COUNT 0
440: #define FLOPS 1
441: #define TIME 2
442: #define MESSAGES 3
443: #define LENGTHS 4
444: #define REDUCTIONS 5
445: static PetscLogDouble EventsType[10][PETSC_LOG_USER_EVENT_HIGH][6];
446: static int EventsStagePrevious = 0;
448: /*@C
449: PetscLogStageRegister - Attaches a charactor string name to a logging stage.
451: Not Collective
453: Input Parameters:
454: + stage - the stage from 0 to 9 inclusive (use PETSC_DETERMINE for current stage)
455: - sname - the name to associate with that stage
457: Notes:
458: The string information (for stage names) is not copied, so the user
459: should NOT change any strings specified here.
461: Level: intermediate
463: .seealso: PetscLogStagePush(), PetscLogStagePop(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
464: @*/
465: int PetscLogStageRegister(int stage,const char sname[])
466: {
470: if (stage == PETSC_DETERMINE) stage = EventsStage;
471: if (stage < 0 || stage > 10) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Stage must be >= 0 and < 10: Instead %d",stage);
472: PetscStrallocpy(sname,&EventsStageName[stage]);
473: return(0);
474: }
476: /*@C
477: PetscLogStagePrint - Tells PetscLogPrintSummary() whether to print this stage or not
479: Collective on PETSC_COMM_WORLD
481: Input Parameters:
482: + stage - the stage from 0 to 9 inclusive (use PETSC_DETERMINE for current stage)
483: - flg - PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE)
485: Level: intermediate
487: .seealso: PetscLogStagePush(), PetscLogStagePop(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
488: @*/
489: int PetscLogStagePrint(int stage,PetscTruth flg)
490: {
492: if (stage == PETSC_DETERMINE) stage = EventsStage;
493: if (stage < 0 || stage > 10) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Stage must be >= 0 and < 10: Instead %d",stage);
494: PetscLogStagePrintFlag[stage] = flg;
495: return(0);
496: }
498: /*@C
499: PetscLogStagePush - Users can log up to 10 stages within a code by using
500: -log_summary in conjunction with PetscLogStagePush() and PetscLogStagePop().
502: Not Collective
504: Input Parameter:
505: . stage - stage on which to log (0 <= stage <= 9)
507: Usage:
508: If the option -log_sumary is used to run the program containing the
509: following code, then 3 sets of summary data will be printed during
510: PetscFinalize().
511: .vb
512: PetscInitialize(int *argc,char ***args,0,0);
513: [stage 0 of code]
514: PetscLogStagePush(1);
515: [stage 1 of code]
516: PetscLogStagePop();
517: PetscBarrier(...);
518: [more stage 0 of code]
519: PetscFinalize();
520: .ve
521:
522: Notes:
523: Use PETSC_DETERMINE to increase the previous stage number (which was poped) by one
524: Use PetscLogStageRegister() to register a name with a stage.
526: Level: intermediate
528: Concepts: logging^stages
530: .seealso: PetscLogStagePop(), PetscLogStageRegister(), PetscBarrier(), PreLoadBegin(), PreLoadEnd(),
531: PreLoadStage()
532: @*/
533: int PetscLogStagePush(int stage)
534: {
536: if (stage == PETSC_DETERMINE) {
537: stage = EventsStagePrevious + 1;
538: }
540: if (stage < 0 || stage > 9) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Stage must be >= 0 < 10: Instead %d",stage);
541: /* record flops/time of previous stage */
542: if (EventsStagePushed) {
543: PetscTimeAdd(EventsStageTime[EventsStage]);
544: EventsStageFlops[EventsStage] += _TotalFlops;
545: EventsStageMessageCounts[EventsStage] += irecv_ct + isend_ct + recv_ct + send_ct;
546: EventsStageMessageLengths[EventsStage] += irecv_len + isend_len + recv_len + send_len;
547: EventsStageReductions[EventsStage] += allreduce_ct;
548: }
549: EventsStageStack[EventsStagePushed] = EventsStage;
550: if (EventsStagePushed++ > 99) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many pushes");
551: EventsStage = stage;
552: if (stage > EventsStageMax) EventsStageMax = stage;
553: PetscTimeSubtract(EventsStageTime[EventsStage]);
554: EventsStageFlops[EventsStage] -= _TotalFlops;
555: EventsStageMessageCounts[EventsStage] -= irecv_ct + isend_ct + recv_ct + send_ct;
556: EventsStageMessageLengths[EventsStage] -= irecv_len + isend_len + recv_len + send_len;
557: EventsStageReductions[EventsStage] -= allreduce_ct;
558: return(0);
559: }
561: /*@C
562: PetscLogStagePop - Users can log up to 10 stages within a code by using
563: -log_summary in conjunction with PetscLogStagePush() and PetscLogStagePop().
565: Not Collective
567: Usage:
568: If the option -log_sumary is used to run the program containing the
569: following code, then 2 sets of summary data will be printed during
570: PetscFinalize().
571: .vb
572: PetscInitialize(int *argc,char ***args,0,0);
573: [stage 0 of code]
574: PetscLogStagePush(1);
575: [stage 1 of code]
576: PetscLogStagePop();
577: PetscBarrier(...);
578: [more stage 0 of code]
579: PetscFinalize();
580: .ve
582: Notes:
583: Use PetscLogStageRegister() to register a stage.
585: Level: intermediate
587: Concepts: logging^stages
589: .seealso: PetscLogStagePush(), PetscLogStageRegister(), PetscBarrier()
590: @*/
591: int PetscLogStagePop(void)
592: {
594: EventsStagePrevious = EventsStage; /* keep a record of too be poped stage */
595: PetscTimeAdd(EventsStageTime[EventsStage]);
596: EventsStageFlops[EventsStage] += _TotalFlops;
597: EventsStageMessageCounts[EventsStage] += irecv_ct + isend_ct + recv_ct + send_ct;
598: EventsStageMessageLengths[EventsStage] += irecv_len + isend_len + recv_len + send_len;
599: EventsStageReductions[EventsStage] += allreduce_ct;
600: if (EventsStagePushed < 1) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many popsn");
601: EventsStage = EventsStageStack[--EventsStagePushed];
602: if (EventsStagePushed) {
603: PetscTimeSubtract(EventsStageTime[EventsStage]);
604: EventsStageFlops[EventsStage] -= _TotalFlops;
605: EventsStageMessageCounts[EventsStage] -= irecv_ct + isend_ct + recv_ct + send_ct;
606: EventsStageMessageLengths[EventsStage] -= irecv_len + isend_len + recv_len + send_len;
607: EventsStageReductions[EventsStage] -= allreduce_ct;
608: }
609: return(0);
610: }
611: /*
612: PetscLogStageDestroy_Private - Destroy the memory allocated during calls to
613: PetscLogStateRegister().
615: */
617: int PetscLogStageDestroy_Private(void)
618: {
619: int i,ierr;
621: for (i=0; i<10; i++) {
622: if (EventsStageName[i]) {
623: PetscFree(EventsStageName[i]);
624: EventsStageName[i] =0;
625: }
626: }
627: return(0);
628: }
630: /* --------------------------------------------------------------------------------*/
632: int (*_PetscLogPHC)(PetscObject)= 0;
633: int (*_PetscLogPHD)(PetscObject)= 0;
634: int (*_PetscLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject) = 0;
635: int (*_PetscLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject) = 0;
637: /*
638: Default object create logger
639: */
640: int PetscLogDefaultPHC(PetscObject obj)
641: {
645: if (nevents >= eventsspace) {
646: Events *tmp;
647: PetscLogDouble end,start;
648: PetscTime(start);
649: tmp = (Events*)malloc((eventsspace+CHUNCK)*sizeof(Events));
650: PetscMemcpy(tmp,events,eventsspace*sizeof(Events));
651: free(events);
652: events = tmp; eventsspace += CHUNCK;
653: PetscTime(end); BaseTime += (end - start);
654: }
655: if (nobjects >= objectsspace) {
656: Objects *tmp;
657: PetscLogDouble end,start;
658: PetscTime(start);
659: tmp = (Objects*)malloc((objectsspace+CHUNCK)*sizeof(Objects));
660: PetscMemcpy(tmp,objects,objectsspace*sizeof(Objects));
661: free(objects);
662: objects = tmp; objectsspace += CHUNCK;
663: PetscTime(end); BaseTime += (end - start);
664: }
665: PetscTime(events[nevents].time); events[nevents].time -= BaseTime;
666: events[nevents].cookie = obj->cookie - PETSC_COOKIE - 1;
667: events[nevents].type = obj->type;
668: events[nevents].id1 = nobjects;
669: events[nevents].id2 = -1;
670: events[nevents].id3 = -1;
671: events[nevents].flops = _TotalFlops;
672: PetscTrSpace(&events[nevents].mem,PETSC_NULL,&events[nevents].maxmem);
673: events[nevents++].event = CREATE;
674: objects[nobjects].parent= -1;
675: objects[nobjects].obj = obj;
676: PetscMemzero(objects[nobjects].string,64*sizeof(char));
677: PetscMemzero(objects[nobjects].name,16*sizeof(char));
678: obj->id = nobjects++;
679: ObjectsType[EventsStage][obj->cookie - PETSC_COOKIE-1][0]++;
680: return(0);
681: }
682: /*
683: Default object destroy logger
684: */
685: int PetscLogDefaultPHD(PetscObject obj)
686: {
687: PetscObject parent;
688: PetscTruth exists;
689: int ierr;
692: if (nevents >= eventsspace) {
693: Events *tmp;
694: PetscLogDouble end,start;
695: PetscTime(start);
696: tmp = (Events*)malloc((eventsspace+CHUNCK)*sizeof(Events));
697: PetscMemcpy(tmp,events,eventsspace*sizeof(Events));
698: free(events);
699: events = tmp; eventsspace += CHUNCK;
700: PetscTime(end); BaseTime += (end - start);
701: }
702: PetscTime(events[nevents].time); events[nevents].time -= BaseTime;
703: events[nevents].event = DESTROY;
704: events[nevents].cookie = obj->cookie - PETSC_COOKIE - 1;
705: events[nevents].type = obj->type;
706: events[nevents].id1 = obj->id;
707: events[nevents].id2 = -1;
708: events[nevents].flops = _TotalFlops;
709: PetscTrSpace(&events[nevents].mem,PETSC_NULL,&events[nevents].maxmem);
710: events[nevents++].id3 = -1;
711: if (obj->parent) {
712: PetscObjectExists(obj->parent,&exists);
713: if (exists) {
714: objects[obj->id].parent = obj->parent->id;
715: } else {
716: objects[obj->id].parent = -1;
717: }
718: } else {
719: objects[obj->id].parent = -1;
720: }
721: if (obj->name) { PetscStrncpy(objects[obj->id].name,obj->name,16);}
722: objects[obj->id].obj = 0;
723: objects[obj->id].mem = obj->mem;
724: ObjectsType[EventsStage][obj->cookie - PETSC_COOKIE-1][1]++;
725: ObjectsType[EventsStage][obj->cookie - PETSC_COOKIE-1][2] += obj->mem;
726: /*
727: Credit all ancestors with your memory
728: */
729: parent = obj->parent;
730: while (parent) {
731: PetscObjectExists(parent,&exists);
732: if (!exists) break;
733: ObjectsType[EventsStage][parent->cookie - PETSC_COOKIE-1][3] += obj->mem;
734: parent = parent->parent;
735: }
736: ObjectsDestroyed++;
737: return(0);
738: }
739: /*
740: Event begin logger with complete logging
741: */
742: int PetscLogDefaultPLBAll(int event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
743: {
744: PetscLogDouble ltime;
745: int ierr;
748: if (nevents >= eventsspace) {
749: Events *tmp;
750: PetscLogDouble end,start;
751: PetscTime(start);
752: tmp = (Events*)malloc((eventsspace+CHUNCK)*sizeof(Events));
753: PetscMemcpy(tmp,events,eventsspace*sizeof(Events));
754: free(events);
755: events = tmp; eventsspace += CHUNCK;
756: PetscTime(end); BaseTime += (end - start);
757: }
758: PetscTime(ltime);
759: events[nevents].time = ltime - BaseTime;
760: if (o1) events[nevents].id1 = o1->id; else events[nevents].id1 = -1;
761: if (o2) events[nevents].id2 = o2->id; else events[nevents].id2 = -1;
762: if (o3) events[nevents].id3 = o3->id; else events[nevents].id3 = -1;
763: events[nevents].type = event;
764: events[nevents].cookie = 0;
765: events[nevents].flops = _TotalFlops;
766: PetscTrSpace(&events[nevents].mem,PETSC_NULL,&events[nevents].maxmem);
767: events[nevents++].event= ACTIONBEGIN;
768: EventsType[EventsStage][event][COUNT]++;
769: EventsType[EventsStage][event][TIME] -= ltime;
770: EventsType[EventsStage][event][FLOPS] -= _TotalFlops;
771: EventsType[EventsStage][event][MESSAGES] -= irecv_ct + isend_ct + recv_ct + send_ct;
772: EventsType[EventsStage][event][LENGTHS] -= irecv_len + isend_len + recv_len + send_len;
773: EventsType[EventsStage][event][REDUCTIONS] -= allreduce_ct;
774: return(0);
775: }
776: /*
777: Event end logger with complete logging
778: */
779: int PetscLogDefaultPLEAll(int event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
780: {
781: PetscLogDouble ltime;
782: int ierr;
785: if (nevents >= eventsspace) {
786: Events *tmp;
787: PetscLogDouble end,start;
788: PetscTime(start);
789: tmp = (Events*)malloc((eventsspace+CHUNCK)*sizeof(Events));
790: PetscMemcpy(tmp,events,eventsspace*sizeof(Events));
791: free(events);
792: events = tmp; eventsspace += CHUNCK;
793: PetscTime(end); BaseTime += (end - start);
794: }
795: PetscTime(ltime);
796: events[nevents].time = ltime - BaseTime;
797: if (o1) events[nevents].id1 = o1->id; else events[nevents].id1 = -1;
798: if (o2) events[nevents].id2 = o2->id; else events[nevents].id2 = -1;
799: if (o3) events[nevents].id3 = o3->id; else events[nevents].id3 = -1;
800: events[nevents].type = event;
801: events[nevents].cookie = 0;
802: events[nevents].flops = _TotalFlops;
803: PetscTrSpace(&events[nevents].mem,PETSC_NULL,&events[nevents].maxmem);
804: events[nevents++].event= ACTIONEND;
805: EventsType[EventsStage][event][TIME] += ltime;
806: EventsType[EventsStage][event][FLOPS] += _TotalFlops;
807: EventsType[EventsStage][event][MESSAGES] += irecv_ct + isend_ct + recv_ct + send_ct;
808: EventsType[EventsStage][event][LENGTHS] += irecv_len + isend_len + recv_len + send_len;
809: EventsType[EventsStage][event][REDUCTIONS] += allreduce_ct;
810: return(0);
811: }
812: /*
813: Default event begin logger
814: */
815: int PetscLogDefaultPLB(int event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
816: {
818: EventsType[EventsStage][event][COUNT]++;
819: PetscTimeSubtract(EventsType[EventsStage][event][TIME]);
820: EventsType[EventsStage][event][FLOPS] -= _TotalFlops;
821: EventsType[EventsStage][event][MESSAGES] -= irecv_ct + isend_ct + recv_ct + send_ct;
822: EventsType[EventsStage][event][LENGTHS] -= irecv_len + isend_len + recv_len + send_len;
823: EventsType[EventsStage][event][REDUCTIONS] -= allreduce_ct;
824: return(0);
825: }
827: /*
828: Default event end logger
829: */
830: int PetscLogDefaultPLE(int event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
831: {
833: PetscTimeAdd(EventsType[EventsStage][event][TIME]);
834: EventsType[EventsStage][event][FLOPS] += _TotalFlops;
835: EventsType[EventsStage][event][MESSAGES] += irecv_ct + isend_ct + recv_ct + send_ct;
836: EventsType[EventsStage][event][LENGTHS] += irecv_len + isend_len + recv_len + send_len;
837: EventsType[EventsStage][event][REDUCTIONS] += allreduce_ct;
838: return(0);
839: }
841: /*
842: Default trace event logging routines
843: */
844: FILE *tracefile = 0;
845: int tracelevel = 0;
846: char *traceblanks = " ";
847: char tracespace[72];
848: PetscLogDouble tracetime = 0.0;
850: int PetscLogDefaultPLBTrace(int event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
851: {
852: int rank,ierr;
853: PetscLogDouble cur_time;
856: if (!tracetime) { PetscTime(tracetime);}
858: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
859: PetscStrncpy(tracespace,traceblanks,2*tracelevel);
860: tracespace[2*tracelevel] = 0;
861: PetscTime(cur_time);
862: fprintf(tracefile,"%s[%d] %g Event begin: %sn",tracespace,rank,cur_time-tracetime,PetscLogEventName[event]);
863: fflush(tracefile);
864: tracelevel++;
866: return(0);
867: }
869: /*
870: Default trace event logging
871: */
872: int PetscLogDefaultPLETrace(int event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
873: {
874: int ierr,rank;
875: PetscLogDouble cur_time;
878: tracelevel--;
879: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
880: PetscStrncpy(tracespace,traceblanks,2*tracelevel);
881: tracespace[2*tracelevel] = 0;
882: PetscTime(cur_time);
883: fprintf(tracefile,"%s[%d] %g Event end: %sn",tracespace,rank,cur_time-tracetime,PetscLogEventName[event]);
884: fflush(tracefile);
885: return(0);
886: }
888: /* -------------------------------------------------------------------------------*/
889: int PetscLogObjectState(PetscObject obj,const char format[],...)
890: {
891: va_list Argp;
894: if (!objects) return(0);
895: va_start(Argp,format);
896: #if defined(PETSC_HAVE_VPRINTF_CHAR)
897: vsprintf(objects[obj->id].string,format,(char *)Argp);
898: #else
899: vsprintf(objects[obj->id].string,format,Argp);
900: #endif
901: va_end(Argp);
902: return(0);
903: }
905: /*@C
906: PetscLogSet - Sets the logging functions called at the beginning and ending
907: of every event.
909: Not Collective
911: Input Parameters:
912: + b - function called at beginning of event
913: - e - function called at end of event
915: Level: developer
917: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogAllBegin(), PetscLogTraceBegin()
919: @*/
920: int PetscLogSet(int (*b)(int,int,PetscObject,PetscObject,PetscObject,PetscObject),
921: int (*e)(int,int,PetscObject,PetscObject,PetscObject,PetscObject))
922: {
924: _PetscLogPLB = b;
925: _PetscLogPLE = e;
926: return(0);
927: }
929: /*@C
930: PetscLogAllBegin - Turns on extensive logging of objects and events. Logs
931: all events. This creates large log files and slows the program down.
933: Not Collective
935: Options Database Keys:
936: . -log_all - Prints extensive log information (for code compiled with PETSC_USE_LOG)
938: Usage:
939: .vb
940: PetscInitialize(...);
941: PetscLogAllBegin();
942: ... code ...
943: PetscLogDump(filename);
944: PetscFinalize();
945: .ve
947: Notes:
948: A related routine is PetscLogBegin (with the options key -log), which is
949: intended for production runs since it logs only flop rates and object
950: creation (and should not significantly slow the programs).
952: Level: advanced
954: Concepts: logging^detailed
956: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogTraceBegin()
957: @*/
958: int PetscLogAllBegin(void)
959: {
963: objects = (Objects*)malloc(CHUNCK*sizeof(Objects));
964: events = (Events*)malloc(CHUNCK*sizeof(Events));
965: _PetscLogPHC = PetscLogDefaultPHC;
966: _PetscLogPHD = PetscLogDefaultPHD;
967: ierr = PetscLogSet(PetscLogDefaultPLBAll,PetscLogDefaultPLEAll);
968: /* all processors sync here for more consistent logging */
969: ierr = MPI_Barrier(PETSC_COMM_WORLD);
970: PetscTime(BaseTime);
971: PetscLogStagePush(0);
972: return(0);
973: }
975: /*@C
976: PetscLogDestroy - Destroys the object and event logging data and resets the
977: global counters.
979: Not Collective
981: Notes:
982: This routine should not usually be used by programmers. Instead employ
983: PetscLogStagePush() and PetscLogStagePop().
985: Level: developer
987: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogStagePush(), PetscLogStagePop()
988: @*/
989: int PetscLogDestroy(void)
990: {
994: if (objects) {free(objects); objects = 0;}
995: if (events) {free(events); events = 0;}
996: ierr = PetscLogSet(0,0);
998: /* Resetting phase */
999: PetscMemzero(EventsType,sizeof(EventsType));
1000: PetscMemzero(ObjectsType,sizeof(ObjectsType));
1001: _TotalFlops = 0.0;
1002: nobjects = 0;
1003: nevents = 0;
1004: ObjectsDestroyed = 0;
1005: return(0);
1006: }
1008: /*@C
1009: PetscLogBegin - Turns on logging of objects and events. This logs flop
1010: rates and object creation and should not slow programs down too much.
1011: This routine may be called more than once.
1013: Collective over PETSC_COMM_WORLD
1015: Options Database Keys:
1016: + -log_summary - Prints summary of flop and timing information to the
1017: screen (for code compiled with PETSC_USE_LOG)
1018: - -log - Prints detailed log information (for code compiled with PETSC_USE_LOG)
1020: Usage:
1021: .vb
1022: PetscInitialize(...);
1023: PetscLogBegin();
1024: ... code ...
1025: PetscLogPrintSummary(MPI_Comm,filename); or PetscLogDump();
1026: PetscFinalize();
1027: .ve
1029: Notes:
1030: PetscLogPrintSummary(MPI_Comm,filename) or PetscLogDump() actually cause the printing of
1031: the logging information.
1033: Level: advanced
1035: Concepts: logging
1037: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogTraceBegin()
1038: @*/
1039: int PetscLogBegin(void)
1040: {
1044: objects = (Objects*)malloc(CHUNCK*sizeof(Objects));
1045: events = (Events*)malloc(CHUNCK*sizeof(Events));
1046: _PetscLogPHC = PetscLogDefaultPHC;
1047: _PetscLogPHD = PetscLogDefaultPHD;
1048: ierr = PetscLogSet(PetscLogDefaultPLB,PetscLogDefaultPLE);
1049: /* all processors sync here for more consistent logging */
1050: ierr = MPI_Barrier(PETSC_COMM_WORLD);
1051: PetscTime(BaseTime);
1052: PetscLogStagePush(0);
1053: return(0);
1054: }
1056: /*@
1057: PetscLogTraceBegin - Activates trace logging. Every time a PETSc event
1058: begins or ends, the event name is printed.
1060: Not Collective
1062: Input Parameter:
1063: . file - file to print trace in (e.g. stdout)
1065: Options Database Key:
1066: . -log_trace [filename] - Activates PetscLogTraceBegin()
1068: Notes:
1069: PetscLogTraceBegin() prints the processor number, the execution time (sec),
1070: then "Event begin:" or "Event end:" followed by the event name.
1072: PetscLogTraceBegin() allows tracing of all PETSc calls, which is useful
1073: to determine where a program is hanging without running in the
1074: debugger. Can be used in conjunction with the -log_info option.
1076: Level: intermediate
1078: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogBegin()
1079: @*/
1080: int PetscLogTraceBegin(FILE *file)
1081: {
1085: ierr = PetscLogSet(PetscLogDefaultPLBTrace,PetscLogDefaultPLETrace);
1086: tracefile = file;
1087: return(0);
1088: }
1090: /*@C
1091: PetscLogDump - Dumps logs of objects to a file. This file is intended to
1092: be read by petsc/bin/petscview.
1094: Collective on PETSC_COMM_WORLD
1096: Input Parameter:
1097: . name - an optional file name
1099: Options Database Keys:
1100: + -log - Prints basic log information (for code compiled with PETSC_USE_LOG)
1101: - -log_all - Prints extensive log information (for code compiled with PETSC_USE_LOG)
1102:
1103: Usage:
1104: .vb
1105: PetscInitialize(...);
1106: PetscLogBegin(); or PetscLogAllBegin();
1107: ... code ...
1108: PetscLogDump(filename);
1109: PetscFinalize();
1110: .ve
1112: Notes:
1113: The default file name is
1114: $ Log.<rank>
1115: where <rank> is the processor number. If no name is specified,
1116: this file will be used.
1118: Level: advanced
1120: Concepts: logging
1122: .seealso: PetscLogBegin(), PetscLogAllBegin(), PetscLogPrintSummary()
1123: @*/
1124: int PetscLogDump(const char sname[])
1125: {
1126: int i,rank,ierr;
1127: FILE *fd;
1128: char file[64],fname[64];
1129: PetscLogDouble flops,_TotalTime;
1130:
1132: PetscTime(_TotalTime);
1133: _TotalTime -= BaseTime;
1135: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
1136: if (sname) sprintf(file,"%s.%d",sname,rank);
1137: else sprintf(file,"Log.%d",rank);
1138: PetscFixFilename(file,fname);
1139: fd = fopen(fname,"w"); if (!fd) SETERRQ1(PETSC_ERR_FILE_OPEN,"cannot open file: %s",fname);
1141: PetscFPrintf(PETSC_COMM_WORLD,fd,"Objects created %d Destroyed %dn",nobjects,ObjectsDestroyed);
1142: PetscFPrintf(PETSC_COMM_WORLD,fd,"Clock Resolution %gn",0.0);
1143: PetscFPrintf(PETSC_COMM_WORLD,fd,"Events %dn",nevents);
1144: for (i=0; i<nevents; i++) {
1145: PetscFPrintf(PETSC_COMM_WORLD,fd,"%g %d %d %d %d %d %d %g %g %gn",events[i].time,
1146: events[i].event,
1147: events[i].cookie,events[i].type,events[i].id1,
1148: events[i].id2,events[i].id3,
1149: events[i].flops,events[i].mem,
1150: events[i].maxmem);
1151: }
1152: for (i=0; i<nobjects; i++) {
1153: PetscFPrintf(PETSC_COMM_WORLD,fd,"%d %dn",objects[i].parent,(int)objects[i].mem);
1154: if (!objects[i].string[0]) {PetscFPrintf(PETSC_COMM_WORLD,fd,"No Infon");}
1155: else {PetscFPrintf(PETSC_COMM_WORLD,fd,"%sn",objects[i].string);}
1156: if (!objects[i].name[0]) {PetscFPrintf(PETSC_COMM_WORLD,fd,"No Namen");}
1157: else {PetscFPrintf(PETSC_COMM_WORLD,fd,"%sn",objects[i].name);}
1158: }
1159: for (i=0; i<PETSC_LOG_USER_EVENT_HIGH; i++) {
1160: flops = 0.0;
1161: if (EventsType[0][i][TIME]){flops = EventsType[0][i][FLOPS]/EventsType[0][i][TIME];}
1162: PetscFPrintf(PETSC_COMM_WORLD,fd,"%d %16g %16g %16g %16gn",i,EventsType[0][i][COUNT],
1163: EventsType[0][i][FLOPS],EventsType[0][i][TIME],flops);
1164: }
1165: PetscFPrintf(PETSC_COMM_WORLD,fd,"Total Flops %14e %16.8en",_TotalFlops,_TotalTime);
1166: fclose(fd);
1167: return(0);
1168: }
1170: extern char *PetscLogEventColor[];
1171: extern int PetscLogEventColorMalloced[];
1173: /*@C
1174: PetscLogEventRegister - Registers an event name for logging operations in
1175: an application code.
1177: Not Collective
1179: Input Parameter:
1180: + string - name associated with the event
1181: - color - (optional) string specifying a color and display pattern
1182: for viewing an event, used by Upshot/Nupshot to view logs
1183: generated by -log_mpe (e.g., - "red:", "green:vlines3");
1184: use PETSC_NULL to let PETSc assign a color.
1185:
1186: Output Parameter:
1187: . e - event id for use with PetscLogEventBegin() and PetscLogEventEnd().
1189: Example of Usage:
1190: .vb
1191: int USER_EVENT;
1192: int user_event_flops;
1193: PetscLogEventRegister(&USER_EVENT,"User event name","EventColor");
1194: PetscLogEventBegin(USER_EVENT,0,0,0,0);
1195: [code segment to monitor]
1196: PetscLogFlops(user_event_flops);
1197: PetscLogEventEnd(USER_EVENT,0,0,0,0);
1198: .ve
1200: Notes:
1201: PETSc automatically logs library events if the code has been
1202: compiled with -DPETSC_USE_LOG (which is the default) and -log,
1203: -log_summary, or -log_all are specified. PetscLogEventRegister() is
1204: intended for logging user events to supplement this PETSc
1205: information.
1207: PETSc can gather data for use with the utilities Upshot/Nupshot
1208: (part of the MPICH distribution). If PETSc has been compiled
1209: with flag -DPETSC_HAVE_MPE (MPE is an additional utility within
1210: MPICH), the user can employ another command line option, -log_mpe,
1211: to create a logfile, "mpe.log", which can be visualized
1212: Upshot/Nupshot. The color argument is used by this utility
1213: in forming the display of this event; the standard X-windows
1214: color names should be used.
1216: Level: intermediate
1218: Concepts: logging^events
1220: .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogFlops(),
1221: PetscLogEventMPEActivate(), PetscLogEventMPEDeactivate(),
1222: PetscLogEventActivate(), PetscLogEventDeactivate()
1223: @*/
1224: int PetscLogEventRegister(int *e,const char string[],const char color[])
1225: {
1226: char *cstring;
1227: int ierr;
1230: *e = PETSC_LOG_USER_EVENT_LOW++;
1231: if (*e > PETSC_LOG_USER_EVENT_HIGH) {
1232: *e = 0;
1233: SETERRQ(PETSC_ERR_PLIB,"Out of event IDs");
1234: }
1235: PetscStrallocpy(string,&cstring);
1236: PetscLogEventName[*e] = cstring;
1237: #if defined(PETSC_HAVE_MPE)
1238: if (UseMPE) {
1239: int rank;
1240: char* ccolor;
1242: PetscLogEventMPEFlags[*e] = 1;
1243: if (color) {
1244: PetscStrallocpy(color,&ccolor);
1245: PetscLogEventColor[*e] = ccolor;
1246: PetscLogEventColorMalloced[*e] = 1;
1247: }
1248: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
1249: if (!rank) {
1250: MPE_Describe_state(MPEBEGIN+2*(*e),MPEBEGIN+2*(*e)+1,cstring,PetscLogEventColor[*e]);
1251: }
1252: }
1253: #endif
1254: return(0);
1255: }
1257: /*
1258: PetscLogEventRegisterDestroy_Private - Destroy the memory allocated during calls to
1259: PetscLogEventRegister().
1261: */
1262: int PetscLogEventRegisterDestroy_Private(void)
1263: {
1264: int i,ierr;
1265:
1267: for (i=PETSC_LOG_USER_EVENT_LOW-1; i>=PETSC_LOG_USER_EVENT_LOW_STATIC; i--) {
1268: PetscFree(PetscLogEventName[i]);
1269: #if defined(PETSC_HAVE_MPE)
1270: if (PetscLogEventColorMalloced[i]) {PetscFree(PetscLogEventColor[i]);}
1271: #endif
1272: }
1273: return(0);
1274: }
1276: /*@
1277: PetscLogEventDeactivate - Indicates that a particular event should not be
1278: logged.
1280: Not Collective
1282: Input Parameter:
1283: . event - integer indicating event
1285: Usage:
1286: .vb
1287: PetscLogEventDeactivate(VEC_SetValues);
1288: [code where you do not want to log VecSetValues()]
1289: PetscLogEventActivate(VEC_SetValues);
1290: [code where you do want to log VecSetValues()]
1291: .ve
1293: Note:
1294: The event may be either a pre-defined PETSc event (found in
1295: include/petsclog.h) or an event number obtained with PetscLogEventRegister()).
1297: Level: advanced
1299: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PetscLogEventActivate()
1300: @*/
1301: int PetscLogEventDeactivate(int event)
1302: {
1304: PetscLogEventFlags[event] = PETSC_FALSE;
1305: return(0);
1306: }
1308: /*@
1309: PetscLogEventActivate - Indicates that a particular event should be logged.
1310: The event may be either a pre-defined PETSc event (found in
1311: include/petsclog.h) or an event number obtained with PetscLogEventRegister().
1313: Not Collective
1315: Input Parameter:
1316: . event - integer indicating event
1318: Usage:
1319: .vb
1320: PetscLogEventDeactivate(VEC_SetValues);
1321: [code where you do not want to log VecSetValues()]
1322: PetscLogEventActivate(VEC_SetValues);
1323: [code where you do want to log VecSetValues()]
1324: .ve
1326: Level: advanced
1328: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PetscLogEventDeactivate()
1329: @*/
1330: int PetscLogEventActivate(int event)
1331: {
1333: PetscLogEventFlags[event] = PETSC_TRUE;
1334: return(0);
1335: }
1337: PetscTruth PetscPreLoadingUsed = PETSC_FALSE;
1338: PetscTruth PetscPreLoadingOn = PETSC_FALSE;
1340: /*@C
1341: PetscLogPrintSummary - Prints a summary of the logging.
1343: Collective over MPI_Comm
1345: Input Parameter:
1346: + comm - MPI communicator (only one processor prints output)
1347: - file - an optional file name
1349: Options Database Keys:
1350: . -log_summary - Prints summary of log information (for code
1351: compiled with PETSC_USE_LOG)
1353: Usage:
1354: .vb
1355: PetscInitialize(...);
1356: PetscLogBegin();
1357: ... code ...
1358: PetscLogPrintSummary(MPI_Comm,filename);
1359: PetscFinalize(...);
1360: .ve
1362: Notes:
1363: By default the summary is printed to stdout.
1364: More extensive examination of the log information can be done with
1365: PetscLogDump(), which is activated by the option -log or -log_all.
1367: Level: beginner
1368:
1369: Concepts: logging^summary
1371: .seealso: PetscLogBegin(), PetscLogDump()
1372: @*/
1373: int PetscLogPrintSummary(MPI_Comm comm,const char filename[])
1374: {
1375: PetscLogDouble maxo,mino,aveo,mem,totmem,maxmem,minmem,mlensmcounts;
1376: PetscLogDouble maxf,minf,avef,totf,_TotalTime,maxt,mint,avet,tott,ratio;
1377: PetscLogDouble fmin,fmax,ftot,wdou,totts,totff,rat,sstime,sflops,ratf;
1378: PetscLogDouble ptotts,ptotff,ptotts_stime,ptotff_sflops,rat1,rat2,rat3;
1379: PetscLogDouble minm,maxm,avem,totm,minr,maxr,maxml,minml,totml,aveml,totr;
1380: PetscLogDouble rp,mp,lp,rpg,mpg,lpg,totms,totmls,totrs,mps,lps,rps,lpmp;
1381: PetscLogDouble pstime,psflops1,psflops,flopr,mict,mact,rct,x,y;
1382: int size,rank,i,j,ierr,lEventsStageMax;
1383: char arch[10],hostname[64],username[16],pname[256],date[64];
1384: FILE *fd = stdout;
1387: /* pop off any stages the user forgot to remove */
1388: while (EventsStagePushed) PetscLogStagePop();
1390: PetscTime(_TotalTime); _TotalTime -= BaseTime;
1391: MPI_Comm_size(comm,&size);
1392: MPI_Comm_rank(comm,&rank);
1394: /* Open the summary file */
1395: PetscFOpen(comm,filename,"w",&fd);
1397: PetscFPrintf(comm,fd,"************************************************************************************************************************n");
1398: PetscFPrintf(comm,fd,"*** WIDEN YOUR WINDOW TO 120 CHARACTERS. Use 'enscript -r -fCourier9' to print this document ***n");
1399: PetscFPrintf(comm,fd,"************************************************************************************************************************n");
1401: PetscFPrintf(comm,fd,"n---------------------------------------------- PETSc Performance Summary: ----------------------------------------------nn");
1402: PetscGetArchType(arch,10);
1403: PetscGetHostName(hostname,64);
1404: PetscGetUserName(username,16);
1405: PetscGetProgramName(pname,256);
1406: PetscGetDate(date,64);
1407: if (size == 1) {
1408: PetscFPrintf(comm,fd,"%s on a %s named %s with %d processor, by %s %sn",
1409: pname,arch,hostname,size,username,date);
1410: } else {
1411: PetscFPrintf(comm,fd,"%s on a %s named %s with %d processors, by %s %sn",
1412: pname,arch,hostname,size,username,date);
1413: }
1414: PetscFPrintf(comm,fd,"Using %sn",PETSC_VERSION_NUMBER);
1417: wdou = _TotalFlops;
1418: MPI_Allreduce(&wdou,&minf,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1419: MPI_Allreduce(&wdou,&maxf,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1420: MPI_Allreduce(&wdou,&totf,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1421: avef = (totf)/((PetscLogDouble) size);
1422: wdou = nobjects;
1423: MPI_Allreduce(&wdou,&mino,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1424: MPI_Allreduce(&wdou,&maxo,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1425: MPI_Allreduce(&wdou,&aveo,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1426: aveo = (aveo)/((PetscLogDouble) size);
1427: wdou = _TotalTime;
1428: MPI_Allreduce(&wdou,&mint,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1429: MPI_Allreduce(&wdou,&maxt,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1430: MPI_Allreduce(&wdou,&tott,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1431: avet = (tott)/((PetscLogDouble) size);
1433: PetscFPrintf(comm,fd,"n Max Max/Min Avg Total n");
1434: if (mint) ratio = maxt/mint; else ratio = 0.0;
1435: PetscFPrintf(comm,fd,"Time (sec): %5.3e %10.5f %5.3en",maxt,ratio,avet);
1436: if (mino) ratio = maxo/mino; else ratio = 0.0;
1437: PetscFPrintf(comm,fd,"Objects: %5.3e %10.5f %5.3en",maxo,ratio,aveo);
1438: if (minf) ratio = maxf/minf; else ratio = 0.0;
1439: PetscFPrintf(comm,fd,"Flops: %5.3e %10.5f %5.3e %5.3en",maxf,ratio,avef,totf);
1441: if (mint) fmin = minf/mint; else fmin = 0;
1442: if (maxt) fmax = maxf/maxt; else fmax = 0;
1443: if (maxt) ftot = totf/maxt; else ftot = 0;
1444: if (fmin) ratio = fmax/fmin; else ratio = 0.0;
1445: PetscFPrintf(comm,fd,"Flops/sec: %5.3e %10.5f %5.3en",fmax,ratio,ftot);
1446: PetscTrSpace(PETSC_NULL,PETSC_NULL,&mem);
1447: if (mem > 0.0) {
1448: MPI_Allreduce(&mem,&maxmem,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1449: MPI_Allreduce(&mem,&minmem,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1450: MPI_Allreduce(&mem,&totmem,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1451: if (minmem) ratio = maxmem/minmem; else ratio = 0.0;
1452: PetscFPrintf(comm,fd,"Memory: %5.3e %8.3f %5.3en",maxmem,ratio,totmem);
1453: }
1454: wdou = .5*(irecv_ct + isend_ct + recv_ct + send_ct);
1455: MPI_Allreduce(&wdou,&minm,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1456: MPI_Allreduce(&wdou,&maxm,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1457: MPI_Allreduce(&wdou,&totm,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1458: avem = (totm)/((PetscLogDouble) size);
1459: wdou = .5*(irecv_len + isend_len + recv_len + send_len);
1460: MPI_Allreduce(&wdou,&minml,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1461: MPI_Allreduce(&wdou,&maxml,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1462: MPI_Allreduce(&wdou,&totml,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1463: if (totm) aveml = (totml)/(totm); else aveml = 0;
1464: if (minm) ratio = maxm/minm; else ratio = 0.0;
1465: PetscFPrintf(comm,fd,"MPI Messages: %5.3e %8.3f %5.3e %5.3en",maxm,ratio,avem,totm);
1466: if (minml) ratio = maxml/minml; else ratio = 0.0;
1467: PetscFPrintf(comm,fd,"MPI Message Lengths: %5.3e %8.3f %5.3e %5.3en",maxml,ratio,aveml,totml);
1468: MPI_Allreduce(&allreduce_ct,&minr,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1469: MPI_Allreduce(&allreduce_ct,&maxr,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1470: MPI_Allreduce(&allreduce_ct,&totr,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1471: if (minr) ratio = maxr/minr; else ratio = 0.0;
1472: PetscFPrintf(comm,fd,"MPI Reductions: %5.3e %8.3fn",maxr,ratio);
1473: PetscFPrintf(comm,fd,"nFlop counting convention: 1 flop = 1 real number operation of type (multiply/divide/add/subtract)n");
1474: PetscFPrintf(comm,fd," e.g., VecAXPY() for real vectors of length N --> 2N flopsn");
1475: PetscFPrintf(comm,fd," and VecAXPY() for complex vectors of length N --> 8N flopsn");
1477: MPI_Allreduce(&EventsStageMax,&lEventsStageMax,1,MPI_INT,MPI_MAX,comm);
1478: if (lEventsStageMax) {
1479: PetscLogDouble mcounts,mlens,rcounts;
1481: PetscFPrintf(comm,fd,"nSummary of Stages: ---- Time ------ ----- Flops ------- -- Messages -- -- Message-lengths -- Reductions --n");
1482: PetscFPrintf(comm,fd," Avg %%Total Avg %%Total counts %%Total avg %%Total counts %%Total n");
1483: for (j=0; j<=lEventsStageMax; j++) {
1484: if (!PetscLogStagePrintFlag[j]) continue;
1486: MPI_Allreduce(&EventsStageFlops[j],&sflops,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1487: MPI_Allreduce(&EventsStageTime[j],&sstime,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1488: if (tott) pstime = 100.0*sstime/tott; else pstime = 0.0;if (pstime >= 99.9) pstime = 99.9;
1489: if (totf) psflops = 100.*sflops/totf; else psflops = 0.0;
1490: if (sstime) psflops1 = (size*sflops)/sstime; else psflops1 = 0.0;
1492: MPI_Allreduce(&EventsStageMessageCounts[j],&mcounts,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1493: MPI_Allreduce(&EventsStageMessageLengths[j],&mlens,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1494: MPI_Allreduce(&EventsStageReductions[j],&rcounts,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1495: mcounts = .5*mcounts; mlens = .5*mlens; rcounts = rcounts/size;
1496: if (totm) rat1 = 100.*mcounts/totm; else rat1 = 0.0; if (rat1 >= 99.9) rat1 = 99.9;
1497: if (totml) rat2 = 100.*mlens/totml; else rat2 = 0.0; if (rat2 >= 99.9) rat2 = 99.9;
1498: if (totr) rat3 = 100.*size*rcounts/totr; else rat3 = 0.0;if (rat3 >= 99.9) rat3 = 99.9;
1499: if (mcounts) mlensmcounts = mlens/mcounts; else mlensmcounts = 0.0;
1500: if (EventsStageName[j]) {
1501: PetscFPrintf(comm,fd," %d: %15s: %6.4e %4.1f%% %6.4e %4.1f%% %5.3e %4.1f%% %5.3e %4.1f%% %5.3e %4.1f%% n",
1502: j,EventsStageName[j],sstime/size,pstime,psflops1,psflops,mcounts,rat1,mlensmcounts,rat2,
1503: rcounts,rat3);
1504: } else {
1505: PetscFPrintf(comm,fd," %d: %6.4e %4.1f%% %6.4e %4.1f%% %5.3e %4.1f%% %5.3e %4.1f%% %5.3e %4.1f%% n",
1506: j,sstime/size,pstime,psflops1,psflops,mcounts,rat1,mlensmcounts,rat2,rcounts,rat3);
1507: }
1508: }
1509: }
1511: PetscFPrintf(comm,fd,
1512: "n------------------------------------------------------------------------------------------------------------------------n");
1513: PetscFPrintf(comm,fd,"See the 'Profiling' chapter of the users' manual for details on interpreting output.n");
1514: PetscFPrintf(comm,fd,"Phase summary info:n");
1515: PetscFPrintf(comm,fd," Count: number of times phase was executedn");
1516: PetscFPrintf(comm,fd," Time and Flops/sec: Max - maximum over all processorsn");
1517: PetscFPrintf(comm,fd," Ratio - ratio of maximum to minimum over all processorsn");
1518: PetscFPrintf(comm,fd," Mess: number of messages sent over all processorsn");
1519: PetscFPrintf(comm,fd," Avg. len: average message length over all processorsn");
1520: PetscFPrintf(comm,fd," Reduct: number of global reductionsn");
1521: PetscFPrintf(comm,fd," Global: entire computationn");
1522: PetscFPrintf(comm,fd," Stage: optional user-defined stages of a computation. Set stages with PetscLogStagePush() and PetscLogStagePop().n");
1523: PetscFPrintf(comm,fd," %%T - percent time in this phase %%F - percent flops in this phasen");
1524: PetscFPrintf(comm,fd," %%M - percent messages in this phase %%L - percent message lengths in this phasen");
1525: PetscFPrintf(comm,fd," %%R - percent reductions in this phasen");
1526: PetscFPrintf(comm,fd," Total Mflop/s: 10e-6 * (sum of flops over all processors)/(max time over all processors)n");
1527: PetscFPrintf(comm,fd,
1528: "------------------------------------------------------------------------------------------------------------------------n");
1530: #if defined(PETSC_USE_BOPT_g)
1531: PetscFPrintf(comm,fd,"nn");
1532: PetscFPrintf(comm,fd," ##########################################################n");
1533: PetscFPrintf(comm,fd," # #n");
1534: PetscFPrintf(comm,fd," # WARNING!!! #n");
1535: PetscFPrintf(comm,fd," # #n");
1536: PetscFPrintf(comm,fd," # This code was compiled with a debugging option, #n");
1537: PetscFPrintf(comm,fd," # BOPT=<g,g_c++,g_complex>. To get timing results #n");
1538: PetscFPrintf(comm,fd," # ALWAYS compile your code with an optimized version, #n");
1539: PetscFPrintf(comm,fd," # BOPT=<O,O_c++,O_complex>; the performance will #n");
1540: PetscFPrintf(comm,fd," # be generally two or three times faster. #n");
1541: PetscFPrintf(comm,fd," # #n");
1542: PetscFPrintf(comm,fd," ##########################################################nnn");
1543: #endif
1544: #if defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_FORTRAN_KERNELS)
1545: PetscFPrintf(comm,fd,"nn");
1546: PetscFPrintf(comm,fd," ##########################################################n");
1547: PetscFPrintf(comm,fd," # #n");
1548: PetscFPrintf(comm,fd," # WARNING!!! #n");
1549: PetscFPrintf(comm,fd," # #n");
1550: PetscFPrintf(comm,fd," # The code for various complex numbers numerical #n");
1551: PetscFPrintf(comm,fd," # kernels uses C++, which generally is not well #n");
1552: PetscFPrintf(comm,fd," # optimized. For performance that is about 4-5 times #n");
1553: PetscFPrintf(comm,fd," # faster, specify the flag -DPETSC_USE_FORTRAN_KERNELS in #n");
1554: PetscFPrintf(comm,fd," # base_variables and recompile the PETSc libraries. #n");
1555: PetscFPrintf(comm,fd," # #n");
1556: PetscFPrintf(comm,fd," ##########################################################nnn");
1557: #endif
1559: if (!PetscPreLoadingUsed) {
1560: PetscFPrintf(comm,fd,"nn");
1561: PetscFPrintf(comm,fd," ##########################################################n");
1562: PetscFPrintf(comm,fd," # #n");
1563: PetscFPrintf(comm,fd," # WARNING!!! #n");
1564: PetscFPrintf(comm,fd," # #n");
1565: PetscFPrintf(comm,fd," # This code was run without the PreLoadinBegin() macros #n");
1566: PetscFPrintf(comm,fd," # To get timing results we always recommend preloading #n");
1567: PetscFPrintf(comm,fd," # otherwise timing numbers may be meaningless. #n");
1568: PetscFPrintf(comm,fd," ##########################################################nnn");
1569: }
1571: /* loop over operations looking for interesting ones */
1572: PetscFPrintf(comm,fd,"Phase Count Time (sec) Flops/sec
1573: --- Global --- --- Stage --- Totaln");
1574: PetscFPrintf(comm,fd," Max Ratio Max Ratio Max Ratio
1575: Mess Avg len Reduct %%T %%F %%M %%L %%R %%T %%F %%M %%L %%R Mflop/sn");
1576: PetscFPrintf(comm,fd,
1577: "------------------------------------------------------------------------------------------------------------------------n");
1578: for (j=0; j<=EventsStageMax; j++) {
1579: if (!PetscLogStagePrintFlag[j]) continue;
1580: MPI_Allreduce(&EventsStageFlops[j],&sflops,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1581: MPI_Allreduce(&EventsStageTime[j],&sstime,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1582: if (EventsStageMax) {
1583: if (EventsStageName[j]) {
1584: PetscFPrintf(comm,fd,"n--- Event Stage %d: %snn",j,EventsStageName[j]);
1585: } else {
1586: PetscFPrintf(comm,fd,"n--- Event Stage %d:nn",j);
1587: }
1588: }
1589: MPI_Allreduce(&EventsStageMessageCounts[j],&totms,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1590: MPI_Allreduce(&EventsStageMessageLengths[j],&totmls,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1591: MPI_Allreduce(&EventsStageReductions[j],&totrs,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1592: /* This loop assumes that PETSC_LOG_USER_EVENT_HIGH is the max event number */
1593: for (i=0; i<PETSC_LOG_USER_EVENT_HIGH; i++) {
1594: if (EventsType[j][i][TIME]) {
1595: wdou = EventsType[j][i][FLOPS]/EventsType[j][i][TIME];
1596: }
1597: else wdou = 0.0;
1598: MPI_Allreduce(&wdou,&minf,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1599: MPI_Allreduce(&wdou,&maxf,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1600: MPI_Allreduce(&EventsType[j][i][FLOPS],&totff,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1601: MPI_Allreduce(&EventsType[j][i][TIME],&mint,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1602: MPI_Allreduce(&EventsType[j][i][TIME],&maxt,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1603: MPI_Allreduce(&EventsType[j][i][TIME],&totts,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1604: MPI_Allreduce(&EventsType[j][i][MESSAGES],&mp,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1605: MPI_Allreduce(&EventsType[j][i][LENGTHS],&lp,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1606: MPI_Allreduce(&EventsType[j][i][REDUCTIONS],&rp,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1608: MPI_Allreduce(&EventsType[j][i][COUNT],&mict,1,MPIU_PETSCLOGDOUBLE,MPI_MIN,comm);
1609: MPI_Allreduce(&EventsType[j][i][COUNT],&mact,1,MPIU_PETSCLOGDOUBLE,MPI_MAX,comm);
1610:
1611: if (maxt) flopr = totff/maxt; else flopr = 0.0;
1613: if (EventsType[j][i][COUNT]) {
1614: if (mint) rat = maxt/mint; else rat = 0.0;
1615: if (minf) ratf = maxf/minf; else ratf = 0.0;
1616: if (tott) ptotts = 100.*totts/tott; else ptotts = 0.0;if (ptotts >= 99.) ptotts = 99.;
1617: if (totf) ptotff = 100.*totff/totf; else ptotff = 0.0;if (ptotff >= 99.) ptotff = 99.;
1618: if (sstime) ptotts_stime = 100.*totts/sstime; else ptotts_stime = 0.0;if (ptotts_stime >= 99.) ptotts_stime = 99.;
1619: if (sflops) ptotff_sflops = 100.*totff/sflops; else ptotff_sflops = 0.0;if (ptotff_sflops >= 99.) ptotff_sflops = 99.;
1620: if (totm) mpg = 100.*mp/totm; else mpg = 0.0; if (mpg >= 99.) mpg = 99.;
1621: if (totml) lpg = 100.*lp/totml; else lpg = 0.0; if (lpg >= 99.) lpg = 99.;
1622: if (totr) rpg = 100.*rp/totr; else rpg = 0.0;if (rpg >= 99.) rpg = 99.;
1623: if (totms) mps = 100.*mp/totms; else mps = 0.0; if (mps >= 99.) mps = 99.;
1624: if (totmls) lps = 100.*lp/totmls; else lps = 0.0; if (lps >= 99.) lps = 99.;
1625: if (totrs) rps = 100.*rp/totrs; else rps = 0.0;if (rps >= 99.) rps = 99.;
1626: if (mp) lpmp = lp/mp; else lpmp = 0.0;
1627: if (mict) rct = mact/mict; else rct = 0.0;
1628: mp = mp/2.0;
1629: rp = rp/((PetscLogDouble) size);
1630: PetscFPrintf(comm,fd,"%-16s %7d %3.1f %5.4e %5.1f %3.2e %6.1f %2.1e %2.1e %2.1e %2.0f %2.0f %2.0f %2.0f %2.0f %2.0f %2.0f %2.0f %2.0f %2.0f %5.0fn",
1631: PetscLogEventName[i],(int)mact,rct,maxt,rat,maxf,ratf,
1632: mp,lpmp,rp,ptotts,ptotff,mpg,lpg,rpg,ptotts_stime,ptotff_sflops,mps,lps,rps,flopr/1.e6);
1633: }
1634: }
1635: /* print effective bandwidth in vector scatters */
1636: if (EventsType[j][VEC_ScatterBarrier][COUNT]) {
1637: MPI_Allreduce(&EventsType[j][i][MESSAGES],&mp,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1638: MPI_Allreduce(&EventsType[j][i][LENGTHS],&lp,1,MPIU_PETSCLOGDOUBLE,MPI_SUM,comm);
1639: }
1641: }
1643: PetscFPrintf(comm,fd,
1644: "------------------------------------------------------------------------------------------------------------------------n");
1645: PetscFPrintf(comm,fd,"n");
1646: PetscFPrintf(comm,fd,"Memory usage is given in bytes:nn");
1648: /* loop over objects looking for interesting ones */
1649: PetscFPrintf(comm,fd,"Object Type Creations Destructions Memory Descendants' Mem.n");
1650: for (j=0; j<=EventsStageMax; j++) {
1651: if (EventsStageMax) {
1652: if (EventsStageName[j]) {
1653: PetscFPrintf(comm,fd,"n--- Event Stage %d: %snn",j,EventsStageName[j]);
1654: } else {
1655: PetscFPrintf(comm,fd,"n--- Event Stage %d:nn",j);
1656: }
1657: }
1658: for (i=0; i<PETSC_MAX_COOKIES; i++) {
1659: if (ObjectsType[j][i][0]) {
1660: PetscFPrintf(comm,fd,"%s %5d %5d %9d %gn",oname[i],(int)
1661: ObjectsType[j][i][0],(int)ObjectsType[j][i][1],(int)ObjectsType[j][i][2],
1662: ObjectsType[j][i][3]);
1663: }
1664: }
1665: }
1667: PetscFPrintf(comm,fd,"===========================================================n");
1668: PetscTime(y);
1669: PetscTime(x);
1670: PetscTime(y);
1671: PetscTime(y);
1672: PetscTime(y);
1673: PetscTime(y);
1674: PetscTime(y);
1675: PetscTime(y);
1676: PetscTime(y);
1677: PetscTime(y);
1678: PetscTime(y);
1679: PetscTime(y);
1680: PetscFPrintf(comm,fd,"Average time to get PetscTime(): %gn",(y-x)/10.0);
1681: if (size > 1) {
1682: int tag;
1683: MPI_Status status;
1685: MPI_Barrier(comm);
1686: PetscTime(x);
1687: MPI_Barrier(comm);
1688: MPI_Barrier(comm);
1689: MPI_Barrier(comm);
1690: MPI_Barrier(comm);
1691: MPI_Barrier(comm);
1692: PetscTime(y);
1693: PetscFPrintf(comm,fd,"Average time for MPI_Barrier(): %gn",(y-x)/5.0);
1694: PetscCommGetNewTag(comm,&tag);
1695: MPI_Barrier(comm);
1696: if (rank) {
1697: MPI_Recv(0,0,MPI_INT,rank-1,tag,comm,&status);
1698: MPI_Send(0,0,MPI_INT,(rank+1)%size,tag,comm);
1699: } else {
1700: PetscTime(x);
1701: MPI_Send(0,0,MPI_INT,1,tag,comm);
1702: MPI_Recv(0,0,MPI_INT,size-1,tag,comm,&status);
1703: PetscTime(y);
1704: PetscFPrintf(comm,fd,"Average time for zero size MPI_Send(): %gn",(y-x)/size);
1705: }
1706: }
1708: #if defined(PETSC_USE_FORTRAN_KERNELS)
1709: PetscFPrintf(comm,fd,"Compiled with FORTRAN kernelsn");
1710: #else
1711: PetscFPrintf(comm,fd,"Compiled without FORTRAN kernelsn");
1712: #endif
1713: #if defined(PETSC_USE_MAT_SINGLE)
1714: PetscFPrintf(comm,fd,"Compiled with single precision matricesn");
1715: #else
1716: PetscFPrintf(comm,fd,"Compiled with double precision matrices (default)n");
1717: #endif
1718: PetscFPrintf(comm,fd,"sizeof(short) %d sizeof(int) %d sizeof(long) %d sizeof(void*)%d",sizeof(short),sizeof(int),sizeof(long),sizeof(void*));
1719: PetscFPrintf(comm,fd,"%s",petscmachineinfo);
1720: PetscFPrintf(comm,fd,"%s",petsccompilerinfo);
1721: PetscFPrintf(comm,fd,"%s",petsccompilerflagsinfo);
1722: PetscFPrintf(comm,fd,"%s",petsclinkerinfo);
1725: PetscFPrintf(comm,fd,"n");
1726: PetscFClose(comm,fd);
1727: return(0);
1728: }
1730: /*@C
1731: PetscGetFlops - Returns the number of flops used on this processor
1732: since the program began.
1734: Not Collective
1736: Output Parameter:
1737: flops - number of floating point operations
1739: Notes:
1740: A global counter logs all PETSc flop counts. The user can use
1741: PetscLogFlops() to increment this counter to include flops for the
1742: application code.
1744: PETSc automatically logs library events if the code has been
1745: compiled with -DPETSC_USE_LOG (which is the default), and -log,
1746: -log_summary, or -log_all are specified. PetscLogFlops() is
1747: intended for logging user flops to supplement this PETSc
1748: information.
1750: Level: intermediate
1752: Concepts: flops^amount done
1754: .seealso: PetscGetTime(), PetscLogFlops()
1755: @*/
1756: int PetscGetFlops(PetscLogDouble *flops)
1757: {
1759: *flops = _TotalFlops;
1760: return(0);
1761: }
1763: /* --------- Activate version ------------- */
1765: /*@
1766: PetscLogEventActivateClass - Activates event logging for a PETSc object class.
1768: Not Collective
1770: Input Parameter:
1771: . cookie - for example MAT_COOKIE, SNES_COOKIE,
1773: Level: developer
1775: .seealso: PetscLogInfoActivate(),PetscLogInfo(),PetscLogInfoAllow(),PetscLogEventDeactivateClass(),
1776: PetscLogEventActivate(),PetscLogEventDeactivate()
1777: @*/
1778: int PetscLogEventActivateClass(int cookie)
1779: {
1781: if (cookie == SNES_COOKIE) {
1782: PetscLogEventActivate(SNES_Solve);
1783: PetscLogEventActivate(SNES_LineSearch);
1784: PetscLogEventActivate(SNES_FunctionEval);
1785: PetscLogEventActivate(SNES_JacobianEval);
1786: PetscLogEventActivate(SNES_MinimizationFunctionEval);
1787: PetscLogEventActivate(SNES_GradientEval);
1788: PetscLogEventActivate(SNES_HessianEval);
1789: } else if (cookie == SLES_COOKIE || cookie == PC_COOKIE || cookie == KSP_COOKIE) {
1790: PetscLogEventActivate(SLES_Solve);
1791: PetscLogEventActivate(SLES_SetUp);
1792: PetscLogEventActivate(KSP_GMRESOrthogonalization);
1793: PetscLogEventActivate(PC_ModifySubMatrices);
1794: PetscLogEventActivate(PC_SetUp);
1795: PetscLogEventActivate(PC_SetUpOnBlocks);
1796: PetscLogEventActivate(PC_Apply);
1797: PetscLogEventActivate(PC_ApplySymmetricLeft);
1798: PetscLogEventActivate(PC_ApplySymmetricRight);
1799: } else if (cookie == MAT_COOKIE) {
1800: PetscLogEventActivate(MAT_Mult);
1801: PetscLogEventActivate(MAT_MatrixFreeMult);
1802: PetscLogEventActivate(MAT_AssemblyBegin);
1803: PetscLogEventActivate(MAT_AssemblyEnd);
1804: PetscLogEventActivate(MAT_GetOrdering);
1805: PetscLogEventActivate(MAT_MultTranspose);
1806: PetscLogEventActivate(MAT_MultAdd);
1807: PetscLogEventActivate(MAT_MultTransposeAdd);
1808: PetscLogEventActivate(MAT_LUFactor);
1809: PetscLogEventActivate(MAT_CholeskyFactor);
1810: PetscLogEventActivate(MAT_LUFactorSymbolic);
1811: PetscLogEventActivate(MAT_ILUFactorSymbolic);
1812: PetscLogEventActivate(MAT_CholeskyFactorSymbolic);
1813: PetscLogEventActivate(MAT_ICCFactorSymbolic);
1814: PetscLogEventActivate(MAT_LUFactorNumeric);
1815: PetscLogEventActivate(MAT_CholeskyFactorNumeric);
1816: PetscLogEventActivate(MAT_CholeskyFactorNumeric);
1817: PetscLogEventActivate(MAT_Relax);
1818: PetscLogEventActivate(MAT_Copy);
1819: PetscLogEventActivate(MAT_Convert);
1820: PetscLogEventActivate(MAT_Scale);
1821: PetscLogEventActivate(MAT_ZeroEntries);
1822: PetscLogEventActivate(MAT_Solve);
1823: PetscLogEventActivate(MAT_SolveAdd);
1824: PetscLogEventActivate(MAT_SolveTranspose);
1825: PetscLogEventActivate(MAT_SolveTransposeAdd);
1826: PetscLogEventActivate(MAT_SetValues);
1827: PetscLogEventActivate(MAT_ForwardSolve);
1828: PetscLogEventActivate(MAT_BackwardSolve);
1829: PetscLogEventActivate(MAT_Load);
1830: PetscLogEventActivate(MAT_View);
1831: PetscLogEventActivate(MAT_ILUFactor);
1833: PetscLogEventActivate(MAT_GetValues);
1834: PetscLogEventActivate(MAT_IncreaseOverlap);
1835: PetscLogEventActivate(MAT_GetRow);
1836: } else if (cookie == VEC_COOKIE) {
1837: PetscLogEventActivate(VEC_Dot);
1838: PetscLogEventActivate(VEC_Norm);
1839: PetscLogEventActivate(VEC_Max);
1840: PetscLogEventActivate(VEC_Min);
1841: PetscLogEventActivate(VEC_TDot);
1842: PetscLogEventActivate(VEC_Scale);
1843: PetscLogEventActivate(VEC_Copy);
1844: PetscLogEventActivate(VEC_Set);
1845: PetscLogEventActivate(VEC_AXPY);
1846: PetscLogEventActivate(VEC_AYPX);
1847: PetscLogEventActivate(VEC_Swap);
1848: PetscLogEventActivate(VEC_WAXPY);
1849: PetscLogEventActivate(VEC_AssemblyBegin);
1850: PetscLogEventActivate(VEC_AssemblyEnd);
1851: PetscLogEventActivate(VEC_MTDot);
1852: PetscLogEventActivate(VEC_MDot);
1853: PetscLogEventActivate(VEC_MAXPY);
1854: PetscLogEventActivate(VEC_PMult);
1855: PetscLogEventActivate(VEC_SetValues);
1856: PetscLogEventActivate(VEC_Load);
1857: PetscLogEventActivate(VEC_View);
1858: PetscLogEventActivate(VEC_ScatterBegin);
1859: PetscLogEventActivate(VEC_ScatterEnd);
1860: PetscLogEventActivate(VEC_SetRandom);
1861: }
1862: return(0);
1863: }
1865: /*@
1866: PetscLogEventDeactivateClass - Deactivates event logging for a PETSc object class.
1868: Not Collective
1870: Input Parameter:
1871: . cookie - for example MAT_COOKIE, SNES_COOKIE,
1873: Level: developer
1875: .seealso: PetscLogInfoActivate(),PetscLogInfo(),PetscLogInfoAllow(),PetscLogEventActivateClass(),
1876: PetscLogEventActivate(),PetscLogEventDeactivate()
1877: @*/
1878: int PetscLogEventDeactivateClass(int cookie)
1879: {
1881: if (cookie == SNES_COOKIE) {
1882: PetscLogEventDeactivate(SNES_Solve);
1883: PetscLogEventDeactivate(SNES_LineSearch);
1884: PetscLogEventDeactivate(SNES_FunctionEval);
1885: PetscLogEventDeactivate(SNES_JacobianEval);
1886: PetscLogEventDeactivate(SNES_MinimizationFunctionEval);
1887: PetscLogEventDeactivate(SNES_GradientEval);
1888: PetscLogEventDeactivate(SNES_HessianEval);
1889: } else if (cookie == SLES_COOKIE || cookie == PC_COOKIE || cookie == KSP_COOKIE) {
1890: PetscLogEventDeactivate(SLES_Solve);
1891: PetscLogEventDeactivate(SLES_SetUp);
1892: PetscLogEventDeactivate(KSP_GMRESOrthogonalization);
1893: PetscLogEventDeactivate(PC_ModifySubMatrices);
1894: PetscLogEventDeactivate(PC_SetUp);
1895: PetscLogEventDeactivate(PC_SetUpOnBlocks);
1896: PetscLogEventDeactivate(PC_Apply);
1897: PetscLogEventDeactivate(PC_ApplySymmetricLeft);
1898: PetscLogEventDeactivate(PC_ApplySymmetricRight);
1899: } else if (cookie == MAT_COOKIE) {
1900: PetscLogEventDeactivate(MAT_Mult);
1901: PetscLogEventDeactivate(MAT_MatrixFreeMult);
1902: PetscLogEventDeactivate(MAT_AssemblyBegin);
1903: PetscLogEventDeactivate(MAT_AssemblyEnd);
1904: PetscLogEventDeactivate(MAT_GetOrdering);
1905: PetscLogEventDeactivate(MAT_MultTranspose);
1906: PetscLogEventDeactivate(MAT_MultAdd);
1907: PetscLogEventDeactivate(MAT_MultTransposeAdd);
1908: PetscLogEventDeactivate(MAT_LUFactor);
1909: PetscLogEventDeactivate(MAT_CholeskyFactor);
1910: PetscLogEventDeactivate(MAT_LUFactorSymbolic);
1911: PetscLogEventDeactivate(MAT_ILUFactorSymbolic);
1912: PetscLogEventDeactivate(MAT_CholeskyFactorSymbolic);
1913: PetscLogEventDeactivate(MAT_ICCFactorSymbolic);
1914: PetscLogEventDeactivate(MAT_LUFactorNumeric);
1915: PetscLogEventDeactivate(MAT_CholeskyFactorNumeric);
1916: PetscLogEventDeactivate(MAT_CholeskyFactorNumeric);
1917: PetscLogEventDeactivate(MAT_Relax);
1918: PetscLogEventDeactivate(MAT_Copy);
1919: PetscLogEventDeactivate(MAT_Convert);
1920: PetscLogEventDeactivate(MAT_Scale);
1921: PetscLogEventDeactivate(MAT_ZeroEntries);
1922: PetscLogEventDeactivate(MAT_Solve);
1923: PetscLogEventDeactivate(MAT_SolveAdd);
1924: PetscLogEventDeactivate(MAT_SolveTranspose);
1925: PetscLogEventDeactivate(MAT_SolveTransposeAdd);
1926: PetscLogEventDeactivate(MAT_SetValues);
1927: PetscLogEventDeactivate(MAT_ForwardSolve);
1928: PetscLogEventDeactivate(MAT_BackwardSolve);
1929: PetscLogEventDeactivate(MAT_Load);
1930: PetscLogEventDeactivate(MAT_View);
1931: PetscLogEventDeactivate(MAT_ILUFactor);
1933: PetscLogEventDeactivate(MAT_GetValues);
1934: PetscLogEventDeactivate(MAT_IncreaseOverlap);
1935: PetscLogEventDeactivate(MAT_GetRow);
1936: } else if (cookie == VEC_COOKIE) {
1937: PetscLogEventDeactivate(VEC_Dot);
1938: PetscLogEventDeactivate(VEC_Norm);
1939: PetscLogEventDeactivate(VEC_Max);
1940: PetscLogEventDeactivate(VEC_Min);
1941: PetscLogEventDeactivate(VEC_TDot);
1942: PetscLogEventDeactivate(VEC_Scale);
1943: PetscLogEventDeactivate(VEC_Copy);
1944: PetscLogEventDeactivate(VEC_Set);
1945: PetscLogEventDeactivate(VEC_AXPY);
1946: PetscLogEventDeactivate(VEC_AYPX);
1947: PetscLogEventDeactivate(VEC_Swap);
1948: PetscLogEventDeactivate(VEC_WAXPY);
1949: PetscLogEventDeactivate(VEC_AssemblyBegin);
1950: PetscLogEventDeactivate(VEC_AssemblyEnd);
1951: PetscLogEventDeactivate(VEC_MTDot);
1952: PetscLogEventDeactivate(VEC_MDot);
1953: PetscLogEventDeactivate(VEC_MAXPY);
1954: PetscLogEventDeactivate(VEC_PMult);
1955: PetscLogEventDeactivate(VEC_SetValues);
1956: PetscLogEventDeactivate(VEC_Load);
1957: PetscLogEventDeactivate(VEC_View);
1958: PetscLogEventDeactivate(VEC_ScatterBegin);
1959: PetscLogEventDeactivate(VEC_ScatterEnd);
1960: PetscLogEventDeactivate(VEC_SetRandom);
1961: }
1962: return(0);
1963: }
1967: /* end of -DPETSC_USE_LOG section */
1968: #else /* -------------------------------------------------------------*/
1970: int PetscLogObjectState(PetscObject obj,const char format[],...)
1971: {
1973: return(0);
1974: }
1976: #endif
1978: /*@
1979: PetscGetTime - Returns the current time of day in seconds. This
1980: returns wall-clock time.
1982: Not Collective
1984: Output Parameter:
1985: . v - time counter
1987: Usage:
1988: .vb
1989: PetscLogDouble v1,v2,elapsed_time;
1990: PetscGetTime(&v1);CHKERR(ierr);
1991: .... perform some calculation ...
1992: PetscGetTime(&v2);CHKERR(ierr);
1993: elapsed_time = v2 - v1;
1994: .ve
1996: Notes:
1997: Since the PETSc libraries incorporate timing of phases and operations,
1998: PetscGetTime() is intended only for timing of application codes.
1999: The options database commands -log, -log_summary, and -log_all activate
2000: PETSc library timing. See the users manual for further details.
2002: Level: intermediate
2004: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStagePush(),
2005: PetscLogStagePop(), PetscLogStageRegister(), PetscGetFlops()
2007: Concepts: time
2008: Concepts: runtime
2010: @*/
2011: int PetscGetTime(PetscLogDouble *t)
2012: {
2014: PetscTime(*t);
2015: return(0);
2016: }
2018: /*MC
2019: PetscLogFlops - Adds floating point operations to the global counter.
2021: Input Parameter:
2022: . f - flop counter
2024: Synopsis:
2025: int PetscLogFlops(int f)
2027: Usage:
2028: .vb
2029: int USER_EVENT;
2030: PetscLogEventRegister(&USER_EVENT,"User event","Color:");
2031: PetscLogEventBegin(USER_EVENT,0,0,0,0);
2032: [code segment to monitor]
2033: PetscLogFlops(user_flops)
2034: PetscLogEventEnd(USER_EVENT,0,0,0,0);
2035: .ve
2037: Notes:
2038: A global counter logs all PETSc flop counts. The user can use
2039: PetscLogFlops() to increment this counter to include flops for the
2040: application code.
2042: PETSc automatically logs library events if the code has been
2043: compiled with -DPETSC_USE_LOG (which is the default), and -log,
2044: -log_summary, or -log_all are specified. PetscLogFlops() is
2045: intended for logging user flops to supplement this PETSc
2046: information.
2048: Level: intermediate
2050: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscGetFlops()
2052: Concepts: flops^logging
2054: M*/
2057: /*MC
2058: PetscLogEventBegin - Logs the beginning of a user event.
2060: Input Parameters:
2061: + e - integer associated with the event obtained from PetscLogEventRegister()
2062: - o1,o2,o3,o4 - objects associated with the event, or 0
2064: Synopsis:
2065: int PetscLogEventBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
2066: PetscObject o4)
2068: Usage:
2069: .vb
2070: int USER_EVENT;
2071: int user_event_flops;
2072: PetscLogEventRegister(&USER_EVENT,"User event","Color:");
2073: PetscLogEventBegin(USER_EVENT,0,0,0,0);
2074: [code segment to monitor]
2075: PetscLogFlops(user_event_flops);
2076: PetscLogEventEnd(USER_EVENT,0,0,0,0);
2077: .ve
2079: Notes:
2080: You should also register each integer event with the command
2081: PetscLogEventRegister(). The source code must be compiled with
2082: -DPETSC_USE_LOG, which is the default.
2084: PETSc automatically logs library events if the code has been
2085: compiled with -DPETSC_USE_LOG, and -log, -log_summary, or -log_all are
2086: specified. PetscLogEventBegin() is intended for logging user events
2087: to supplement this PETSc information.
2089: Level: intermediate
2091: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops()
2093: Concepts: logging^events
2095: M*/
2097: /*MC
2098: PetscLogEventEnd - Log the end of a user event.
2100: Input Parameters:
2101: + e - integer associated with the event obtained with PetscLogEventRegister()
2102: - o1,o2,o3,o4 - objects associated with the event, or 0
2104: Synopsis:
2105: int PetscLogEventEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
2106: PetscObject o4)
2108: Usage:
2109: .vb
2110: int USER_EVENT;
2111: int user_event_flops;
2112: PetscLogEventRegister(&USER_EVENT,"User event","Color:");
2113: PetscLogEventBegin(USER_EVENT,0,0,0,0);
2114: [code segment to monitor]
2115: PetscLogFlops(user_event_flops);
2116: PetscLogEventEnd(USER_EVENT,0,0,0,0);
2117: .ve
2119: Notes:
2120: You should also register each additional integer event with the command
2121: PetscLogEventRegister(). Source code must be compiled with
2122: -DPETSC_USE_LOG, which is the default.
2124: PETSc automatically logs library events if the code has been
2125: compiled with -DPETSC_USE_LOG, and -log, -log_summary, or -log_all are
2126: specified. PetscLogEventEnd() is intended for logging user events
2127: to supplement this PETSc information.
2129: Level: intermediate
2131: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogFlops()
2133: Concepts: logging^events
2135: M*/
2137: /*MC
2138: PetscLogEventBarrierBegin - Logs the time in a barrier before an event.
2140: Input Parameters:
2141: . e - integer associated with the event obtained from PetscLogEventRegister()
2142: . o1,o2,o3,o4 - objects associated with the event, or 0
2143: . comm - communicator the barrier takes place over
2145: Synopsis:
2146: int PetscLogEventBarrierBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
2147: PetscObject o4,MPI_Comm comm)
2149: Usage:
2150: .vb
2151: PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm);
2152: Code
2153: PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm);
2154: .ve
2156: Notes:
2157: This is for logging the amount of time spent in a barrier for an event
2158: that requires synchronization.
2160: Additional Notes:
2161: Synchronization events always come in pairs; for example, VEC_NormBarrier and
2162: VEC_Norm = VEC_NormBarrier + 1
2164: Level: developer
2166: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(),
2167: PetscLogEventBarrierEnd()
2169: Concepts: logging^events
2171: M*/
2173: /*MC
2174: PetscLogEventBarrierEnd - Logs the time in a barrier before an event.
2176: Input Parameters:
2177: . e - integer associated with the event obtained from PetscLogEventRegister()
2178: . o1,o2,o3,o4 - objects associated with the event, or 0
2179: . comm - communicator the barrier takes place over
2181: Synopsis:
2182: int PetscLogEventBarrierEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
2183: PetscObject o4,MPI_Comm comm)
2185: Usage:
2186: .vb
2187: PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm);
2188: Code
2189: PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm);
2190: .ve
2192: Notes:
2193: This is for logging the amount of time spent in a barrier for an event
2194: that requires synchronization.
2196: Additional Notes:
2197: Synchronization events always come in pairs; for example, VEC_NormBarrier and
2198: VEC_Norm = VEC_NormBarrier + 1
2200: Level: developer
2202: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(),
2203: PetscLogEventBarrierBegin()
2205: Concepts: logging^events
2207: M*/
2209: /*MC
2210: PreLoadBegin - Begin a segment of code that may be preloaded (run twice)
2211: to get accurate timings
2213: Input Parameter:
2214: + flag - PETSC_TRUE to run twice, PETSC_FALSE to run once, may be overridden
2215: with command line option -preload true or -preload false
2216: - name - name of first stage (lines of code timed seperately with -log_summary) to
2217: be preloaded
2219: Synopsis:
2220: void PreLoadBegin(PetscTruth flag,char *name);
2222: Usage:
2223: .vb
2224: PreLoadBegin(PETSC_TRUE,"first stage);
2225: lines of code
2226: PreLoadStage("second stage");
2227: lines of code
2228: PreLoadEnd();
2229: .ve
2231: Level: intermediate
2233: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadEnd(), PreLoadStage()
2235: Concepts: preloading
2236: Concepts: timing^accurate
2237: Concepts: paging^eliminating effects of
2240: M*/
2242: /*MC
2243: PreLoadEnd - End a segment of code that may be preloaded (run twice)
2244: to get accurate timings
2246: Synopsis:
2247: void PreLoadEnd(void);
2249: Usage:
2250: .vb
2251: PreLoadBegin(PETSC_TRUE,"first stage);
2252: lines of code
2253: PreLoadStage("second stage");
2254: lines of code
2255: PreLoadEnd();
2256: .ve
2258: Level: intermediate
2260: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadStage()
2262: M*/
2264: /*MC
2265: PreLoadStage - Start a new segment of code to be timed seperately.
2266: to get accurate timings
2268: Synopsis:
2269: void PreLoadStage(char *name);
2271: Usage:
2272: .vb
2273: PreLoadBegin(PETSC_TRUE,"first stage);
2274: lines of code
2275: PreLoadStage("second stage");
2276: lines of code
2277: PreLoadEnd();
2278: .ve
2280: Level: intermediate
2282: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd()
2284: M*/