Actual source code: eventlog.c
petsc-3.5.4 2015-05-23
2: /*
3: This defines part of the private API for logging performance information. It is intended to be used only by the
4: PETSc PetscLog...() interface and not elsewhere, nor by users. Hence the prototypes for these functions are NOT
5: in the public PETSc include files.
7: */
8: #include <petsc-private/logimpl.h> /*I "petscsys.h" I*/
10: /*----------------------------------------------- Creation Functions -------------------------------------------------*/
11: /* Note: these functions do not have prototypes in a public directory, so they are considered "internal" and not exported. */
15: /*@C
16: EventRegLogCreate - This creates a PetscEventRegLog object.
18: Not collective
20: Input Parameter:
21: . eventLog - The PetscEventRegLog
23: Level: developer
25: .keywords: log, event, create
26: .seealso: EventRegLogDestroy(), PetscStageLogCreate()
27: @*/
28: PetscErrorCode EventRegLogCreate(PetscEventRegLog *eventLog)
29: {
30: PetscEventRegLog l;
31: PetscErrorCode ierr;
34: PetscNew(&l);
35: l->numEvents = 0;
36: l->maxEvents = 100;
37: PetscMalloc1(l->maxEvents, &l->eventInfo);
38: *eventLog = l;
39: return(0);
40: }
44: /*@C
45: EventRegLogDestroy - This destroys a PetscEventRegLog object.
47: Not collective
49: Input Paramter:
50: . eventLog - The PetscEventRegLog
52: Level: developer
54: .keywords: log, event, destroy
55: .seealso: EventRegLogCreate()
56: @*/
57: PetscErrorCode EventRegLogDestroy(PetscEventRegLog eventLog)
58: {
59: int e;
63: for (e = 0; e < eventLog->numEvents; e++) {
64: PetscFree(eventLog->eventInfo[e].name);
65: }
66: PetscFree(eventLog->eventInfo);
67: PetscFree(eventLog);
68: return(0);
69: }
73: /*@C
74: EventPerfLogCreate - This creates a PetscEventPerfLog object.
76: Not collective
78: Input Parameter:
79: . eventLog - The PetscEventPerfLog
81: Level: developer
83: .keywords: log, event, create
84: .seealso: EventPerfLogDestroy(), PetscStageLogCreate()
85: @*/
86: PetscErrorCode EventPerfLogCreate(PetscEventPerfLog *eventLog)
87: {
88: PetscEventPerfLog l;
89: PetscErrorCode ierr;
92: PetscNew(&l);
93: l->numEvents = 0;
94: l->maxEvents = 100;
95: PetscMalloc1(l->maxEvents, &l->eventInfo);
96: *eventLog = l;
97: return(0);
98: }
102: /*@C
103: EventPerfLogDestroy - This destroys a PetscEventPerfLog object.
105: Not collective
107: Input Paramter:
108: . eventLog - The PetscEventPerfLog
110: Level: developer
112: .keywords: log, event, destroy
113: .seealso: EventPerfLogCreate()
114: @*/
115: PetscErrorCode EventPerfLogDestroy(PetscEventPerfLog eventLog)
116: {
120: PetscFree(eventLog->eventInfo);
121: PetscFree(eventLog);
122: return(0);
123: }
125: /*------------------------------------------------ General Functions -------------------------------------------------*/
128: /*@C
129: EventPerfInfoClear - This clears a PetscEventPerfInfo object.
131: Not collective
133: Input Paramter:
134: . eventInfo - The PetscEventPerfInfo
136: Level: developer
138: .keywords: log, event, destroy
139: .seealso: EventPerfLogCreate()
140: @*/
141: PetscErrorCode EventPerfInfoClear(PetscEventPerfInfo *eventInfo)
142: {
144: eventInfo->id = -1;
145: eventInfo->active = PETSC_TRUE;
146: eventInfo->visible = PETSC_TRUE;
147: eventInfo->depth = 0;
148: eventInfo->count = 0;
149: eventInfo->flops = 0.0;
150: eventInfo->flops2 = 0.0;
151: eventInfo->flopsTmp = 0.0;
152: eventInfo->time = 0.0;
153: eventInfo->time2 = 0.0;
154: eventInfo->timeTmp = 0.0;
155: eventInfo->numMessages = 0.0;
156: eventInfo->messageLength = 0.0;
157: eventInfo->numReductions = 0.0;
158: return(0);
159: }
163: /*@C
164: EventPerfInfoCopy - Copy the activity and visibility data in eventInfo to outInfo
166: Not collective
168: Input Paramter:
169: . eventInfo - The input PetscEventPerfInfo
171: Output Paramter:
172: . outInfo - The output PetscEventPerfInfo
174: Level: developer
176: .keywords: log, event, copy
177: .seealso: EventPerfInfoClear()
178: @*/
179: PetscErrorCode EventPerfInfoCopy(PetscEventPerfInfo *eventInfo, PetscEventPerfInfo *outInfo)
180: {
182: outInfo->id = eventInfo->id;
183: outInfo->active = eventInfo->active;
184: outInfo->visible = eventInfo->visible;
185: return(0);
186: }
190: /*@C
191: EventPerfLogEnsureSize - This ensures that a PetscEventPerfLog is at least of a certain size.
193: Not collective
195: Input Paramters:
196: + eventLog - The PetscEventPerfLog
197: - size - The size
199: Level: developer
201: .keywords: log, event, size, ensure
202: .seealso: EventPerfLogCreate()
203: @*/
204: PetscErrorCode EventPerfLogEnsureSize(PetscEventPerfLog eventLog, int size)
205: {
206: PetscEventPerfInfo *eventInfo;
207: PetscErrorCode ierr;
210: while (size > eventLog->maxEvents) {
211: PetscMalloc1(eventLog->maxEvents*2, &eventInfo);
212: PetscMemcpy(eventInfo, eventLog->eventInfo, eventLog->maxEvents * sizeof(PetscEventPerfInfo));
213: PetscFree(eventLog->eventInfo);
215: eventLog->eventInfo = eventInfo;
216: eventLog->maxEvents *= 2;
217: }
218: while (eventLog->numEvents < size) {
219: EventPerfInfoClear(&eventLog->eventInfo[eventLog->numEvents++]);
220: }
221: return(0);
222: }
224: #if defined(PETSC_HAVE_MPE)
225: #include <mpe.h>
226: PETSC_INTERN PetscErrorCode PetscLogMPEGetRGBColor(const char*[]);
229: PetscErrorCode PetscLogEventBeginMPE(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
230: {
231: PetscErrorCode ierr;
234: MPE_Log_event(petsc_stageLog->eventLog->eventInfo[event].mpe_id_begin,0,NULL);
235: return(0);
236: }
240: PetscErrorCode PetscLogEventEndMPE(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
241: {
242: PetscErrorCode ierr;
245: MPE_Log_event(petsc_stageLog->eventLog->eventInfo[event].mpe_id_end,0,NULL);
246: return(0);
247: }
248: #endif
250: /*--------------------------------------------- Registration Functions ----------------------------------------------*/
253: /*@C
254: EventRegLogRegister - Registers an event for logging operations in an application code.
256: Not Collective
258: Input Parameters:
259: + eventLog - The EventLog
260: . ename - The name associated with the event
261: - classid - The classid associated to the class for this event
263: Output Parameter:
264: . event - The event
266: Example of Usage:
267: .vb
268: int USER_EVENT;
269: PetscLogDouble user_event_flops;
270: PetscLogEventRegister("User event name",0,&USER_EVENT);
271: PetscLogEventBegin(USER_EVENT,0,0,0,0);
272: [code segment to monitor]
273: PetscLogFlops(user_event_flops);
274: PetscLogEventEnd(USER_EVENT,0,0,0,0);
275: .ve
277: Notes:
278: PETSc automatically logs library events if the code has been
279: compiled with -DPETSC_USE_LOG (which is the default) and -log,
280: -log_summary, or -log_all are specified. PetscLogEventRegister() is
281: intended for logging user events to supplement this PETSc
282: information.
284: PETSc can gather data for use with the utilities Jumpshot
285: (part of the MPICH distribution). If PETSc has been compiled
286: with flag -DPETSC_HAVE_MPE (MPE is an additional utility within
287: MPICH), the user can employ another command line option, -log_mpe,
288: to create a logfile, "mpe.log", which can be visualized
289: Jumpshot.
291: Level: developer
293: .keywords: log, event, register
294: .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventMPEActivate(), PetscLogEventMPEDeactivate(),
295: EventLogActivate(), EventLogDeactivate()
296: @*/
297: PetscErrorCode EventRegLogRegister(PetscEventRegLog eventLog, const char ename[], PetscClassId classid, PetscLogEvent *event)
298: {
299: PetscEventRegInfo *eventInfo;
300: char *str;
301: int e;
302: PetscErrorCode ierr;
307: /* Should check classid I think */
308: e = eventLog->numEvents++;
309: if (eventLog->numEvents > eventLog->maxEvents) {
310: PetscMalloc1(eventLog->maxEvents*2, &eventInfo);
311: PetscMemcpy(eventInfo, eventLog->eventInfo, eventLog->maxEvents * sizeof(PetscEventRegInfo));
312: PetscFree(eventLog->eventInfo);
314: eventLog->eventInfo = eventInfo;
315: eventLog->maxEvents *= 2;
316: }
317: PetscStrallocpy(ename, &str);
319: eventLog->eventInfo[e].name = str;
320: eventLog->eventInfo[e].classid = classid;
321: #if defined(PETSC_HAVE_MPE)
322: if (PetscLogPLB == PetscLogEventBeginMPE) {
323: const char *color;
324: PetscMPIInt rank;
325: int beginID, endID;
327: beginID = MPE_Log_get_event_number();
328: endID = MPE_Log_get_event_number();
330: eventLog->eventInfo[e].mpe_id_begin = beginID;
331: eventLog->eventInfo[e].mpe_id_end = endID;
333: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
334: if (!rank) {
335: PetscLogMPEGetRGBColor(&color);
336: MPE_Describe_state(beginID, endID, str, (char*)color);
337: }
338: }
339: #endif
340: *event = e;
341: return(0);
342: }
344: /*---------------------------------------------- Activation Functions -----------------------------------------------*/
347: /*@C
348: EventPerfLogActivate - Indicates that a particular event should be logged.
350: Not Collective
352: Input Parameters:
353: + eventLog - The PetscEventPerfLog
354: - event - The event
356: Usage:
357: .vb
358: EventPerfLogDeactivate(log, VEC_SetValues);
359: [code where you do not want to log VecSetValues()]
360: EventPerfLogActivate(log, VEC_SetValues);
361: [code where you do want to log VecSetValues()]
362: .ve
364: Note:
365: The event may be either a pre-defined PETSc event (found in
366: include/petsclog.h) or an event number obtained with EventRegLogRegister().
368: Level: developer
370: .keywords: log, event, activate
371: .seealso: PetscLogEventMPEDeactivate(), PetscLogEventMPEActivate(), EventPerfLogDeactivate()
372: @*/
373: PetscErrorCode EventPerfLogActivate(PetscEventPerfLog eventLog, PetscLogEvent event)
374: {
376: eventLog->eventInfo[event].active = PETSC_TRUE;
377: return(0);
378: }
382: /*@C
383: EventPerfLogDeactivate - Indicates that a particular event should not be logged.
385: Not Collective
387: Input Parameters:
388: + eventLog - The PetscEventPerfLog
389: - event - The event
391: Usage:
392: .vb
393: EventPerfLogDeactivate(log, VEC_SetValues);
394: [code where you do not want to log VecSetValues()]
395: EventPerfLogActivate(log, VEC_SetValues);
396: [code where you do want to log VecSetValues()]
397: .ve
399: Note:
400: The event may be either a pre-defined PETSc event (found in
401: include/petsclog.h) or an event number obtained with EventRegLogRegister().
403: Level: developer
405: .keywords: log, event, activate
406: .seealso: PetscLogEventMPEDeactivate(), PetscLogEventMPEActivate(), EventPerfLogActivate()
407: @*/
408: PetscErrorCode EventPerfLogDeactivate(PetscEventPerfLog eventLog, PetscLogEvent event)
409: {
411: eventLog->eventInfo[event].active = PETSC_FALSE;
412: return(0);
413: }
417: /*@C
418: EventPerfLogActivateClass - Activates event logging for a PETSc object class.
420: Not Collective
422: Input Parameters:
423: + eventLog - The PetscEventPerfLog
424: . eventRegLog - The PetscEventRegLog
425: - classid - The class id, for example MAT_CLASSID, SNES_CLASSID,
427: Level: developer
429: .seealso: EventPerfLogDeactivateClass(), EventPerfLogActivate(), EventPerfLogDeactivate()
430: @*/
431: PetscErrorCode EventPerfLogActivateClass(PetscEventPerfLog eventLog, PetscEventRegLog eventRegLog, PetscClassId classid)
432: {
433: int e;
436: for (e = 0; e < eventLog->numEvents; e++) {
437: int c = eventRegLog->eventInfo[e].classid;
438: if (c == classid) eventLog->eventInfo[e].active = PETSC_TRUE;
439: }
440: return(0);
441: }
445: /*@C
446: EventPerfLogDeactivateClass - Deactivates event logging for a PETSc object class.
448: Not Collective
450: Input Parameters:
451: + eventLog - The PetscEventPerfLog
452: . eventRegLog - The PetscEventRegLog
453: - classid - The class id, for example MAT_CLASSID, SNES_CLASSID,
455: Level: developer
457: .seealso: EventPerfLogDeactivateClass(), EventPerfLogDeactivate(), EventPerfLogActivate()
458: @*/
459: PetscErrorCode EventPerfLogDeactivateClass(PetscEventPerfLog eventLog, PetscEventRegLog eventRegLog, PetscClassId classid)
460: {
461: int e;
464: for (e = 0; e < eventLog->numEvents; e++) {
465: int c = eventRegLog->eventInfo[e].classid;
466: if (c == classid) eventLog->eventInfo[e].active = PETSC_FALSE;
467: }
468: return(0);
469: }
471: /*------------------------------------------------ Query Functions --------------------------------------------------*/
474: /*@C
475: EventRegLogGetEvent - This function returns the event id given the event name.
477: Not Collective
479: Input Parameters:
480: + eventLog - The PetscEventRegLog
481: - name - The stage name
483: Output Parameter:
484: . event - The event id, or -1 if not found
486: Level: developer
488: .keywords: log, stage
489: .seealso: EventRegLogRegister()
490: @*/
491: PetscErrorCode EventRegLogGetEvent(PetscEventRegLog eventLog, const char name[], PetscLogEvent *event)
492: {
493: PetscBool match;
494: int e;
500: *event = -1;
501: for (e = 0; e < eventLog->numEvents; e++) {
502: PetscStrcasecmp(eventLog->eventInfo[e].name, name, &match);
503: if (match) {
504: *event = e;
505: break;
506: }
507: }
508: return(0);
509: }
513: /*@C
514: EventPerfLogSetVisible - This function determines whether an event is printed during PetscLogView()
516: Not Collective
518: Input Parameters:
519: + eventLog - The PetscEventPerfLog
520: . event - The event to log
521: - isVisible - The visibility flag, PETSC_TRUE for printing, otherwise PETSC_FALSE (default is PETSC_TRUE)
523: Database Options:
524: . -log_summary - Activates log summary
526: Level: developer
528: .keywords: log, visible, event
529: .seealso: EventPerfLogGetVisible(), EventRegLogRegister(), PetscStageLogGetEventLog()
530: @*/
531: PetscErrorCode EventPerfLogSetVisible(PetscEventPerfLog eventLog, PetscLogEvent event, PetscBool isVisible)
532: {
534: eventLog->eventInfo[event].visible = isVisible;
535: return(0);
536: }
540: /*@C
541: EventPerfLogGetVisible - This function returns whether an event is printed during PetscLogView()
543: Not Collective
545: Input Parameters:
546: + eventLog - The PetscEventPerfLog
547: - event - The event id to log
549: Output Parameter:
550: . isVisible - The visibility flag, PETSC_TRUE for printing, otherwise PETSC_FALSE (default is PETSC_TRUE)
552: Database Options:
553: . -log_summary - Activates log summary
555: Level: developer
557: .keywords: log, visible, event
558: .seealso: EventPerfLogSetVisible(), EventRegLogRegister(), PetscStageLogGetEventLog()
559: @*/
560: PetscErrorCode EventPerfLogGetVisible(PetscEventPerfLog eventLog, PetscLogEvent event, PetscBool *isVisible)
561: {
564: *isVisible = eventLog->eventInfo[event].visible;
565: return(0);
566: }
570: PetscErrorCode PetscLogEventGetFlops(PetscLogEvent event, PetscLogDouble *flops)
571: {
572: PetscStageLog stageLog;
573: PetscEventPerfLog eventLog = NULL;
574: int stage;
575: PetscErrorCode ierr;
578: PetscLogGetStageLog(&stageLog);
579: PetscStageLogGetCurrent(stageLog, &stage);
580: PetscStageLogGetEventPerfLog(stageLog, stage, &eventLog);
581: *flops = eventLog->eventInfo[event].flops;
582: return(0);
583: }
587: PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent event)
588: {
589: PetscStageLog stageLog;
590: PetscEventPerfLog eventLog = NULL;
591: int stage;
592: PetscErrorCode ierr;
595: PetscLogGetStageLog(&stageLog);
596: PetscStageLogGetCurrent(stageLog, &stage);
597: PetscStageLogGetEventPerfLog(stageLog, stage, &eventLog);
599: eventLog->eventInfo[event].flops = 0.0;
600: eventLog->eventInfo[event].flops2 = 0.0;
601: eventLog->eventInfo[event].flopsTmp = 0.0;
602: return(0);
603: }
605: #if defined(PETSC_HAVE_CHUD)
606: #include <CHUD/CHUD.h>
607: #endif
608: #if defined(PETSC_HAVE_PAPI)
609: #include <papi.h>
610: extern int PAPIEventSet;
611: #endif
615: PetscErrorCode PetscLogEventBeginDefault(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
616: {
617: PetscStageLog stageLog;
618: PetscEventPerfLog eventLog = NULL;
619: int stage;
620: PetscErrorCode ierr;
623: PetscLogGetStageLog(&stageLog);
624: PetscStageLogGetCurrent(stageLog, &stage);
625: PetscStageLogGetEventPerfLog(stageLog, stage, &eventLog);
626: /* Check for double counting */
627: eventLog->eventInfo[event].depth++;
628: if (eventLog->eventInfo[event].depth > 1) return(0);
629: /* Log performance info */
630: eventLog->eventInfo[event].count++;
631: eventLog->eventInfo[event].timeTmp = 0.0;
632: PetscTimeSubtract(&eventLog->eventInfo[event].timeTmp);
633: eventLog->eventInfo[event].flopsTmp = 0.0;
634: #if defined(PETSC_HAVE_CHUD)
635: eventLog->eventInfo[event].flopsTmp -= chudGetPMCEventCount(chudCPU1Dev,PMC_1);
636: #elif defined(PETSC_HAVE_PAPI)
637: { long_long values[2];
638: PAPI_read(PAPIEventSet,values);
640: eventLog->eventInfo[event].flopsTmp -= values[0];
641: /* printf("fma %g flops %g\n",(double)values[1],(double)values[0]); */
642: }
643: #else
644: eventLog->eventInfo[event].flopsTmp -= petsc_TotalFlops;
645: #endif
646: eventLog->eventInfo[event].numMessages -= petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
647: eventLog->eventInfo[event].messageLength -= petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
648: eventLog->eventInfo[event].numReductions -= petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
649: return(0);
650: }
654: PetscErrorCode PetscLogEventEndDefault(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
655: {
656: PetscStageLog stageLog;
657: PetscEventPerfLog eventLog = NULL;
658: int stage;
659: PetscErrorCode ierr;
662: PetscLogGetStageLog(&stageLog);
663: PetscStageLogGetCurrent(stageLog, &stage);
664: PetscStageLogGetEventPerfLog(stageLog, stage, &eventLog);
665: /* Check for double counting */
666: eventLog->eventInfo[event].depth--;
667: if (eventLog->eventInfo[event].depth > 0) return(0);
668: else if (eventLog->eventInfo[event].depth < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Logging event had unbalanced begin/end pairs");
669: /* Log performance info */
670: PetscTimeAdd(&eventLog->eventInfo[event].timeTmp);
671: eventLog->eventInfo[event].time += eventLog->eventInfo[event].timeTmp;
672: eventLog->eventInfo[event].time2 += eventLog->eventInfo[event].timeTmp*eventLog->eventInfo[event].timeTmp;
673: #if defined(PETSC_HAVE_CHUD)
674: eventLog->eventInfo[event].flopsTmp += chudGetPMCEventCount(chudCPU1Dev,PMC_1);
675: #elif defined(PETSC_HAVE_PAPI)
676: { long_long values[2];
677: PAPI_read(PAPIEventSet,values);
679: eventLog->eventInfo[event].flopsTmp += values[0];
680: /* printf("fma %g flops %g\n",(double)values[1],(double)values[0]); */
681: }
682: #else
683: eventLog->eventInfo[event].flopsTmp += petsc_TotalFlops;
684: #endif
685: eventLog->eventInfo[event].flops += eventLog->eventInfo[event].flopsTmp;
686: eventLog->eventInfo[event].flops2 += eventLog->eventInfo[event].flopsTmp*eventLog->eventInfo[event].flopsTmp;
687: eventLog->eventInfo[event].numMessages += petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
688: eventLog->eventInfo[event].messageLength += petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
689: eventLog->eventInfo[event].numReductions += petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
690: return(0);
691: }
695: PetscErrorCode PetscLogEventBeginComplete(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
696: {
697: PetscStageLog stageLog;
698: PetscEventRegLog eventRegLog;
699: PetscEventPerfLog eventPerfLog = NULL;
700: Action *tmpAction;
701: PetscLogDouble start, end;
702: PetscLogDouble curTime;
703: int stage;
704: PetscErrorCode ierr;
707: /* Dynamically enlarge logging structures */
708: if (petsc_numActions >= petsc_maxActions) {
709: PetscTime(&start);
710: PetscMalloc1(petsc_maxActions*2, &tmpAction);
711: PetscMemcpy(tmpAction, petsc_actions, petsc_maxActions * sizeof(Action));
712: PetscFree(petsc_actions);
714: petsc_actions = tmpAction;
715: petsc_maxActions *= 2;
716: PetscTime(&end);
717: petsc_BaseTime += (end - start);
718: }
719: /* Record the event */
720: PetscLogGetStageLog(&stageLog);
721: PetscStageLogGetCurrent(stageLog, &stage);
722: PetscStageLogGetEventRegLog(stageLog, &eventRegLog);
723: PetscStageLogGetEventPerfLog(stageLog, stage, &eventPerfLog);
724: PetscTime(&curTime);
725: if (petsc_logActions) {
726: petsc_actions[petsc_numActions].time = curTime - petsc_BaseTime;
727: petsc_actions[petsc_numActions].action = ACTIONBEGIN;
728: petsc_actions[petsc_numActions].event = event;
729: petsc_actions[petsc_numActions].classid = eventRegLog->eventInfo[event].classid;
730: if (o1) petsc_actions[petsc_numActions].id1 = o1->id;
731: else petsc_actions[petsc_numActions].id1 = -1;
732: if (o2) petsc_actions[petsc_numActions].id2 = o2->id;
733: else petsc_actions[petsc_numActions].id2 = -1;
734: if (o3) petsc_actions[petsc_numActions].id3 = o3->id;
735: else petsc_actions[petsc_numActions].id3 = -1;
736: petsc_actions[petsc_numActions].flops = petsc_TotalFlops;
738: PetscMallocGetCurrentUsage(&petsc_actions[petsc_numActions].mem);
739: PetscMallocGetMaximumUsage(&petsc_actions[petsc_numActions].maxmem);
740: petsc_numActions++;
741: }
742: /* Check for double counting */
743: eventPerfLog->eventInfo[event].depth++;
744: if (eventPerfLog->eventInfo[event].depth > 1) return(0);
745: /* Log the performance info */
746: eventPerfLog->eventInfo[event].count++;
747: eventPerfLog->eventInfo[event].time -= curTime;
748: eventPerfLog->eventInfo[event].flops -= petsc_TotalFlops;
749: eventPerfLog->eventInfo[event].numMessages -= petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
750: eventPerfLog->eventInfo[event].messageLength -= petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
751: eventPerfLog->eventInfo[event].numReductions -= petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
752: return(0);
753: }
757: PetscErrorCode PetscLogEventEndComplete(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
758: {
759: PetscStageLog stageLog;
760: PetscEventRegLog eventRegLog;
761: PetscEventPerfLog eventPerfLog = NULL;
762: Action *tmpAction;
763: PetscLogDouble start, end;
764: PetscLogDouble curTime;
765: int stage;
766: PetscErrorCode ierr;
769: /* Dynamically enlarge logging structures */
770: if (petsc_numActions >= petsc_maxActions) {
771: PetscTime(&start);
772: PetscMalloc1(petsc_maxActions*2, &tmpAction);
773: PetscMemcpy(tmpAction, petsc_actions, petsc_maxActions * sizeof(Action));
774: PetscFree(petsc_actions);
776: petsc_actions = tmpAction;
777: petsc_maxActions *= 2;
778: PetscTime(&end);
779: petsc_BaseTime += (end - start);
780: }
781: /* Record the event */
782: PetscLogGetStageLog(&stageLog);
783: PetscStageLogGetCurrent(stageLog, &stage);
784: PetscStageLogGetEventRegLog(stageLog, &eventRegLog);
785: PetscStageLogGetEventPerfLog(stageLog, stage, &eventPerfLog);
786: PetscTime(&curTime);
787: if (petsc_logActions) {
788: petsc_actions[petsc_numActions].time = curTime - petsc_BaseTime;
789: petsc_actions[petsc_numActions].action = ACTIONEND;
790: petsc_actions[petsc_numActions].event = event;
791: petsc_actions[petsc_numActions].classid = eventRegLog->eventInfo[event].classid;
792: if (o1) petsc_actions[petsc_numActions].id1 = o1->id;
793: else petsc_actions[petsc_numActions].id1 = -1;
794: if (o2) petsc_actions[petsc_numActions].id2 = o2->id;
795: else petsc_actions[petsc_numActions].id2 = -1;
796: if (o3) petsc_actions[petsc_numActions].id3 = o3->id;
797: else petsc_actions[petsc_numActions].id3 = -1;
798: petsc_actions[petsc_numActions].flops = petsc_TotalFlops;
800: PetscMallocGetCurrentUsage(&petsc_actions[petsc_numActions].mem);
801: PetscMallocGetMaximumUsage(&petsc_actions[petsc_numActions].maxmem);
802: petsc_numActions++;
803: }
804: /* Check for double counting */
805: eventPerfLog->eventInfo[event].depth--;
806: if (eventPerfLog->eventInfo[event].depth > 0) return(0);
807: else if (eventPerfLog->eventInfo[event].depth < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Logging event had unbalanced begin/end pairs");
808: /* Log the performance info */
809: eventPerfLog->eventInfo[event].count++;
810: eventPerfLog->eventInfo[event].time += curTime;
811: eventPerfLog->eventInfo[event].flops += petsc_TotalFlops;
812: eventPerfLog->eventInfo[event].numMessages += petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
813: eventPerfLog->eventInfo[event].messageLength += petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
814: eventPerfLog->eventInfo[event].numReductions += petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
815: return(0);
816: }
820: PetscErrorCode PetscLogEventBeginTrace(PetscLogEvent event, int t, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
821: {
822: PetscStageLog stageLog;
823: PetscEventRegLog eventRegLog;
824: PetscEventPerfLog eventPerfLog = NULL;
825: PetscLogDouble cur_time;
826: PetscMPIInt rank;
827: int stage,err;
828: PetscErrorCode ierr;
831: if (!petsc_tracetime) PetscTime(&petsc_tracetime);
833: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
834: PetscLogGetStageLog(&stageLog);
835: PetscStageLogGetCurrent(stageLog, &stage);
836: PetscStageLogGetEventRegLog(stageLog, &eventRegLog);
837: PetscStageLogGetEventPerfLog(stageLog, stage, &eventPerfLog);
838: /* Check for double counting */
839: eventPerfLog->eventInfo[event].depth++;
840: petsc_tracelevel++;
841: if (eventPerfLog->eventInfo[event].depth > 1) return(0);
842: /* Log performance info */
843: PetscTime(&cur_time);
844: PetscFPrintf(PETSC_COMM_SELF,petsc_tracefile, "%s[%d] %g Event begin: %s\n", petsc_tracespace, rank, cur_time-petsc_tracetime, eventRegLog->eventInfo[event].name);
845: PetscStrncpy(petsc_tracespace, petsc_traceblanks, 2*petsc_tracelevel);
847: petsc_tracespace[2*petsc_tracelevel] = 0;
849: err = fflush(petsc_tracefile);
850: if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
851: return(0);
852: }
856: PetscErrorCode PetscLogEventEndTrace(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
857: {
858: PetscStageLog stageLog;
859: PetscEventRegLog eventRegLog;
860: PetscEventPerfLog eventPerfLog = NULL;
861: PetscLogDouble cur_time;
862: int stage,err;
863: PetscMPIInt rank;
864: PetscErrorCode ierr;
867: petsc_tracelevel--;
868: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
869: PetscLogGetStageLog(&stageLog);
870: PetscStageLogGetCurrent(stageLog, &stage);
871: PetscStageLogGetEventRegLog(stageLog, &eventRegLog);
872: PetscStageLogGetEventPerfLog(stageLog, stage, &eventPerfLog);
873: /* Check for double counting */
874: eventPerfLog->eventInfo[event].depth--;
875: if (eventPerfLog->eventInfo[event].depth > 0) return(0);
876: else if (eventPerfLog->eventInfo[event].depth < 0 || petsc_tracelevel < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Logging event had unbalanced begin/end pairs");
878: /* Log performance info */
879: PetscStrncpy(petsc_tracespace, petsc_traceblanks, 2*petsc_tracelevel);
881: petsc_tracespace[2*petsc_tracelevel] = 0;
882: PetscTime(&cur_time);
883: PetscFPrintf(PETSC_COMM_SELF,petsc_tracefile, "%s[%d] %g Event end: %s\n", petsc_tracespace, rank, cur_time-petsc_tracetime, eventRegLog->eventInfo[event].name);
884: err = fflush(petsc_tracefile);
885: if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
886: return(0);
887: }