Actual source code: eventlog.c
petsc-3.14.6 2021-03-30
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>
10: PetscBool PetscLogSyncOn = PETSC_FALSE;
11: PetscBool PetscLogMemory = PETSC_FALSE;
12: #if defined(PETSC_HAVE_DEVICE)
13: PetscBool PetscLogGpuTraffic = PETSC_FALSE;
14: #endif
16: /*----------------------------------------------- Creation Functions -------------------------------------------------*/
17: /* Note: these functions do not have prototypes in a public directory, so they are considered "internal" and not exported. */
19: /*@C
20: PetscEventRegLogCreate - This creates a PetscEventRegLog object.
22: Not collective
24: Input Parameter:
25: . eventLog - The PetscEventRegLog
27: Level: developer
29: .seealso: PetscEventRegLogDestroy(), PetscStageLogCreate()
30: @*/
31: PetscErrorCode PetscEventRegLogCreate(PetscEventRegLog *eventLog)
32: {
33: PetscEventRegLog l;
34: PetscErrorCode ierr;
37: PetscNew(&l);
38: l->numEvents = 0;
39: l->maxEvents = 100;
40: PetscMalloc1(l->maxEvents,&l->eventInfo);
41: *eventLog = l;
42: return(0);
43: }
45: /*@C
46: PetscEventRegLogDestroy - This destroys a PetscEventRegLog object.
48: Not collective
50: Input Parameter:
51: . eventLog - The PetscEventRegLog
53: Level: developer
55: .seealso: PetscEventRegLogCreate()
56: @*/
57: PetscErrorCode PetscEventRegLogDestroy(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: }
71: /*@C
72: PetscEventPerfLogCreate - This creates a PetscEventPerfLog object.
74: Not collective
76: Input Parameter:
77: . eventLog - The PetscEventPerfLog
79: Level: developer
81: .seealso: PetscEventPerfLogDestroy(), PetscStageLogCreate()
82: @*/
83: PetscErrorCode PetscEventPerfLogCreate(PetscEventPerfLog *eventLog)
84: {
85: PetscEventPerfLog l;
86: PetscErrorCode ierr;
89: PetscNew(&l);
90: l->numEvents = 0;
91: l->maxEvents = 100;
92: PetscCalloc1(l->maxEvents,&l->eventInfo);
93: *eventLog = l;
94: return(0);
95: }
97: /*@C
98: PetscEventPerfLogDestroy - This destroys a PetscEventPerfLog object.
100: Not collective
102: Input Parameter:
103: . eventLog - The PetscEventPerfLog
105: Level: developer
107: .seealso: PetscEventPerfLogCreate()
108: @*/
109: PetscErrorCode PetscEventPerfLogDestroy(PetscEventPerfLog eventLog)
110: {
114: PetscFree(eventLog->eventInfo);
115: PetscFree(eventLog);
116: return(0);
117: }
119: /*------------------------------------------------ General Functions -------------------------------------------------*/
120: /*@C
121: PetscEventPerfInfoClear - This clears a PetscEventPerfInfo object.
123: Not collective
125: Input Parameter:
126: . eventInfo - The PetscEventPerfInfo
128: Level: developer
130: .seealso: PetscEventPerfLogCreate()
131: @*/
132: PetscErrorCode PetscEventPerfInfoClear(PetscEventPerfInfo *eventInfo)
133: {
135: eventInfo->id = -1;
136: eventInfo->active = PETSC_TRUE;
137: eventInfo->visible = PETSC_TRUE;
138: eventInfo->depth = 0;
139: eventInfo->count = 0;
140: eventInfo->flops = 0.0;
141: eventInfo->flops2 = 0.0;
142: eventInfo->flopsTmp = 0.0;
143: eventInfo->time = 0.0;
144: eventInfo->time2 = 0.0;
145: eventInfo->timeTmp = 0.0;
146: eventInfo->syncTime = 0.0;
147: eventInfo->dof[0] = -1.0;
148: eventInfo->dof[1] = -1.0;
149: eventInfo->dof[2] = -1.0;
150: eventInfo->dof[3] = -1.0;
151: eventInfo->dof[4] = -1.0;
152: eventInfo->dof[5] = -1.0;
153: eventInfo->dof[6] = -1.0;
154: eventInfo->dof[7] = -1.0;
155: eventInfo->errors[0] = -1.0;
156: eventInfo->errors[1] = -1.0;
157: eventInfo->errors[2] = -1.0;
158: eventInfo->errors[3] = -1.0;
159: eventInfo->errors[4] = -1.0;
160: eventInfo->errors[5] = -1.0;
161: eventInfo->errors[6] = -1.0;
162: eventInfo->errors[7] = -1.0;
163: eventInfo->numMessages = 0.0;
164: eventInfo->messageLength = 0.0;
165: eventInfo->numReductions = 0.0;
166: #if defined(PETSC_HAVE_DEVICE)
167: eventInfo->CpuToGpuCount = 0.0;
168: eventInfo->GpuToCpuCount = 0.0;
169: eventInfo->CpuToGpuSize = 0.0;
170: eventInfo->GpuToCpuSize = 0.0;
171: eventInfo->GpuFlops = 0.0;
172: eventInfo->GpuTime = 0.0;
173: #endif
174: return(0);
175: }
177: /*@C
178: PetscEventPerfInfoCopy - Copy the activity and visibility data in eventInfo to outInfo
180: Not collective
182: Input Parameter:
183: . eventInfo - The input PetscEventPerfInfo
185: Output Parameter:
186: . outInfo - The output PetscEventPerfInfo
188: Level: developer
190: .seealso: PetscEventPerfInfoClear()
191: @*/
192: PetscErrorCode PetscEventPerfInfoCopy(PetscEventPerfInfo *eventInfo,PetscEventPerfInfo *outInfo)
193: {
195: outInfo->id = eventInfo->id;
196: outInfo->active = eventInfo->active;
197: outInfo->visible = eventInfo->visible;
198: return(0);
199: }
201: /*@C
202: PetscEventPerfLogEnsureSize - This ensures that a PetscEventPerfLog is at least of a certain size.
204: Not collective
206: Input Parameters:
207: + eventLog - The PetscEventPerfLog
208: - size - The size
210: Level: developer
212: .seealso: PetscEventPerfLogCreate()
213: @*/
214: PetscErrorCode PetscEventPerfLogEnsureSize(PetscEventPerfLog eventLog,int size)
215: {
216: PetscEventPerfInfo *eventInfo;
217: PetscErrorCode ierr;
220: while (size > eventLog->maxEvents) {
221: PetscCalloc1(eventLog->maxEvents*2,&eventInfo);
222: PetscArraycpy(eventInfo,eventLog->eventInfo,eventLog->maxEvents);
223: PetscFree(eventLog->eventInfo);
224: eventLog->eventInfo = eventInfo;
225: eventLog->maxEvents *= 2;
226: }
227: while (eventLog->numEvents < size) {
228: PetscEventPerfInfoClear(&eventLog->eventInfo[eventLog->numEvents++]);
229: }
230: return(0);
231: }
233: #if defined(PETSC_HAVE_MPE)
234: #include <mpe.h>
235: PETSC_INTERN PetscErrorCode PetscLogMPEGetRGBColor(const char*[]);
236: PetscErrorCode PetscLogEventBeginMPE(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
237: {
238: PetscErrorCode ierr;
241: MPE_Log_event(petsc_stageLog->eventLog->eventInfo[event].mpe_id_begin,0,NULL);
242: return(0);
243: }
245: PetscErrorCode PetscLogEventEndMPE(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
246: {
247: PetscErrorCode ierr;
250: MPE_Log_event(petsc_stageLog->eventLog->eventInfo[event].mpe_id_end,0,NULL);
251: return(0);
252: }
253: #endif
255: /*--------------------------------------------- Registration Functions ----------------------------------------------*/
256: /*@C
257: PetscEventRegLogRegister - Registers an event for logging operations in an application code.
259: Not Collective
261: Input Parameters:
262: + eventLog - The PetscEventLog
263: . ename - The name associated with the event
264: - classid - The classid associated to the class for this event
266: Output Parameter:
267: . event - The event
269: Example of Usage:
270: .vb
271: int USER_EVENT;
272: PetscLogDouble user_event_flops;
273: PetscLogEventRegister("User event name",0,&USER_EVENT);
274: PetscLogEventBegin(USER_EVENT,0,0,0,0);
275: [code segment to monitor]
276: PetscLogFlops(user_event_flops);
277: PetscLogEventEnd(USER_EVENT,0,0,0,0);
278: .ve
280: Notes:
282: PETSc can gather data for use with the utilities Jumpshot
283: (part of the MPICH distribution). If PETSc has been compiled
284: with flag -DPETSC_HAVE_MPE (MPE is an additional utility within
285: MPICH), the user can employ another command line option, -log_mpe,
286: to create a logfile, "mpe.log", which can be visualized
287: Jumpshot.
289: Level: developer
291: .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogFlops(),
292: PetscEventLogActivate(), PetscEventLogDeactivate()
293: @*/
294: PetscErrorCode PetscEventRegLogRegister(PetscEventRegLog eventLog,const char ename[],PetscClassId classid,PetscLogEvent *event)
295: {
296: PetscEventRegInfo *eventInfo;
297: char *str;
298: int e;
299: PetscErrorCode ierr;
304: /* Should check classid I think */
305: e = eventLog->numEvents++;
306: if (eventLog->numEvents > eventLog->maxEvents) {
307: PetscCalloc1(eventLog->maxEvents*2,&eventInfo);
308: PetscArraycpy(eventInfo,eventLog->eventInfo,eventLog->maxEvents);
309: PetscFree(eventLog->eventInfo);
310: eventLog->eventInfo = eventInfo;
311: eventLog->maxEvents *= 2;
312: }
313: PetscStrallocpy(ename,&str);
315: eventLog->eventInfo[e].name = str;
316: eventLog->eventInfo[e].classid = classid;
317: eventLog->eventInfo[e].collective = PETSC_TRUE;
318: #if defined(PETSC_HAVE_MPE)
319: if (PetscLogPLB == PetscLogEventBeginMPE) {
320: const char *color;
321: PetscMPIInt rank;
322: int beginID,endID;
324: beginID = MPE_Log_get_event_number();
325: endID = MPE_Log_get_event_number();
327: eventLog->eventInfo[e].mpe_id_begin = beginID;
328: eventLog->eventInfo[e].mpe_id_end = endID;
330: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
331: if (!rank) {
332: PetscLogMPEGetRGBColor(&color);
333: MPE_Describe_state(beginID,endID,str,(char*)color);
334: }
335: }
336: #endif
337: *event = e;
338: return(0);
339: }
341: /*---------------------------------------------- Activation Functions -----------------------------------------------*/
342: /*@C
343: PetscEventPerfLogActivate - Indicates that a particular event should be logged.
345: Not Collective
347: Input Parameters:
348: + eventLog - The PetscEventPerfLog
349: - event - The event
351: Usage:
352: .vb
353: PetscEventPerfLogDeactivate(log, VEC_SetValues);
354: [code where you do not want to log VecSetValues()]
355: PetscEventPerfLogActivate(log, VEC_SetValues);
356: [code where you do want to log VecSetValues()]
357: .ve
359: Note:
360: The event may be either a pre-defined PETSc event (found in
361: include/petsclog.h) or an event number obtained with PetscEventRegLogRegister().
363: Level: developer
365: .seealso: PetscEventPerfLogDeactivate()
366: @*/
367: PetscErrorCode PetscEventPerfLogActivate(PetscEventPerfLog eventLog,PetscLogEvent event)
368: {
370: eventLog->eventInfo[event].active = PETSC_TRUE;
371: return(0);
372: }
374: /*@C
375: PetscEventPerfLogDeactivate - Indicates that a particular event should not be logged.
377: Not Collective
379: Input Parameters:
380: + eventLog - The PetscEventPerfLog
381: - event - The event
383: Usage:
384: .vb
385: PetscEventPerfLogDeactivate(log, VEC_SetValues);
386: [code where you do not want to log VecSetValues()]
387: PetscEventPerfLogActivate(log, VEC_SetValues);
388: [code where you do want to log VecSetValues()]
389: .ve
391: Note:
392: The event may be either a pre-defined PETSc event (found in
393: include/petsclog.h) or an event number obtained with PetscEventRegLogRegister().
395: Level: developer
397: .seealso: PetscEventPerfLogActivate()
398: @*/
399: PetscErrorCode PetscEventPerfLogDeactivate(PetscEventPerfLog eventLog,PetscLogEvent event)
400: {
402: eventLog->eventInfo[event].active = PETSC_FALSE;
403: return(0);
404: }
406: /*@C
407: PetscEventPerfLogActivateClass - Activates event logging for a PETSc object class.
409: Not Collective
411: Input Parameters:
412: + eventLog - The PetscEventPerfLog
413: . eventRegLog - The PetscEventRegLog
414: - classid - The class id, for example MAT_CLASSID, SNES_CLASSID,
416: Level: developer
418: .seealso: PetscEventPerfLogDeactivateClass(), PetscEventPerfLogActivate(), PetscEventPerfLogDeactivate()
419: @*/
420: PetscErrorCode PetscEventPerfLogActivateClass(PetscEventPerfLog eventLog,PetscEventRegLog eventRegLog,PetscClassId classid)
421: {
422: int e;
425: for (e = 0; e < eventLog->numEvents; e++) {
426: int c = eventRegLog->eventInfo[e].classid;
427: if (c == classid) eventLog->eventInfo[e].active = PETSC_TRUE;
428: }
429: return(0);
430: }
432: /*@C
433: PetscEventPerfLogDeactivateClass - Deactivates event logging for a PETSc object class.
435: Not Collective
437: Input Parameters:
438: + eventLog - The PetscEventPerfLog
439: . eventRegLog - The PetscEventRegLog
440: - classid - The class id, for example MAT_CLASSID, SNES_CLASSID,
442: Level: developer
444: .seealso: PetscEventPerfLogDeactivateClass(), PetscEventPerfLogDeactivate(), PetscEventPerfLogActivate()
445: @*/
446: PetscErrorCode PetscEventPerfLogDeactivateClass(PetscEventPerfLog eventLog,PetscEventRegLog eventRegLog,PetscClassId classid)
447: {
448: int e;
451: for (e = 0; e < eventLog->numEvents; e++) {
452: int c = eventRegLog->eventInfo[e].classid;
453: if (c == classid) eventLog->eventInfo[e].active = PETSC_FALSE;
454: }
455: return(0);
456: }
458: /*------------------------------------------------ Query Functions --------------------------------------------------*/
459: /*@C
460: PetscEventRegLogGetEvent - This function returns the event id given the event name.
462: Not Collective
464: Input Parameters:
465: + eventLog - The PetscEventRegLog
466: - name - The stage name
468: Output Parameter:
469: . event - The event id, or -1 if not found
471: Level: developer
473: .seealso: PetscEventRegLogRegister()
474: @*/
475: PetscErrorCode PetscEventRegLogGetEvent(PetscEventRegLog eventLog,const char name[],PetscLogEvent *event)
476: {
477: PetscBool match;
478: int e;
484: *event = -1;
485: for (e = 0; e < eventLog->numEvents; e++) {
486: PetscStrcasecmp(eventLog->eventInfo[e].name,name,&match);
487: if (match) {
488: *event = e;
489: break;
490: }
491: }
492: return(0);
493: }
495: /*@C
496: PetscEventPerfLogSetVisible - This function determines whether an event is printed during PetscLogView()
498: Not Collective
500: Input Parameters:
501: + eventLog - The PetscEventPerfLog
502: . event - The event to log
503: - isVisible - The visibility flag, PETSC_TRUE for printing, otherwise PETSC_FALSE (default is PETSC_TRUE)
505: Database Options:
506: . -log_view - Activates log summary
508: Level: developer
510: .seealso: PetscEventPerfLogGetVisible(), PetscEventRegLogRegister(), PetscStageLogGetEventLog()
511: @*/
512: PetscErrorCode PetscEventPerfLogSetVisible(PetscEventPerfLog eventLog,PetscLogEvent event,PetscBool isVisible)
513: {
515: eventLog->eventInfo[event].visible = isVisible;
516: return(0);
517: }
519: /*@C
520: PetscEventPerfLogGetVisible - This function returns whether an event is printed during PetscLogView()
522: Not Collective
524: Input Parameters:
525: + eventLog - The PetscEventPerfLog
526: - event - The event id to log
528: Output Parameter:
529: . isVisible - The visibility flag, PETSC_TRUE for printing, otherwise PETSC_FALSE (default is PETSC_TRUE)
531: Database Options:
532: . -log_view - Activates log summary
534: Level: developer
536: .seealso: PetscEventPerfLogSetVisible(), PetscEventRegLogRegister(), PetscStageLogGetEventLog()
537: @*/
538: PetscErrorCode PetscEventPerfLogGetVisible(PetscEventPerfLog eventLog,PetscLogEvent event,PetscBool *isVisible)
539: {
542: *isVisible = eventLog->eventInfo[event].visible;
543: return(0);
544: }
546: /*@C
547: PetscLogEventGetPerfInfo - Return the performance information about the given event in the given stage
549: Input Parameters:
550: + stage - The stage number or PETSC_DETERMINE for the current stage
551: - event - The event number
553: Output Parameters:
554: . info - This structure is filled with the performance information
556: Level: Intermediate
558: .seealso: PetscLogEventGetFlops()
559: @*/
560: PetscErrorCode PetscLogEventGetPerfInfo(int stage,PetscLogEvent event,PetscEventPerfInfo *info)
561: {
562: PetscStageLog stageLog;
563: PetscEventPerfLog eventLog = NULL;
564: PetscErrorCode ierr;
568: if (!PetscLogPLB) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Must use -log_view or PetscLogDefaultBegin() before calling this routine");
569: PetscLogGetStageLog(&stageLog);
570: if (stage < 0) {PetscStageLogGetCurrent(stageLog,&stage);}
571: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
572: *info = eventLog->eventInfo[event];
573: return(0);
574: }
576: PetscErrorCode PetscLogEventGetFlops(PetscLogEvent event,PetscLogDouble *flops)
577: {
578: PetscStageLog stageLog;
579: PetscEventPerfLog eventLog = NULL;
580: int stage;
581: PetscErrorCode ierr;
584: if (!PetscLogPLB) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Must use -log_view or PetscLogDefaultBegin() before calling this routine");
585: PetscLogGetStageLog(&stageLog);
586: PetscStageLogGetCurrent(stageLog,&stage);
587: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
588: *flops = eventLog->eventInfo[event].flops;
589: return(0);
590: }
592: PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent event)
593: {
594: PetscStageLog stageLog;
595: PetscEventPerfLog eventLog = NULL;
596: int stage;
597: PetscErrorCode ierr;
600: PetscLogGetStageLog(&stageLog);
601: PetscStageLogGetCurrent(stageLog,&stage);
602: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
604: eventLog->eventInfo[event].flops = 0.0;
605: eventLog->eventInfo[event].flops2 = 0.0;
606: eventLog->eventInfo[event].flopsTmp = 0.0;
607: return(0);
608: }
610: PetscErrorCode PetscLogEventSynchronize(PetscLogEvent event,MPI_Comm comm)
611: {
612: PetscStageLog stageLog;
613: PetscEventRegLog eventRegLog;
614: PetscEventPerfLog eventLog = NULL;
615: int stage;
616: PetscLogDouble time = 0.0;
617: PetscErrorCode ierr;
620: if (!PetscLogSyncOn || comm == MPI_COMM_NULL) return(0);
621: PetscLogGetStageLog(&stageLog);
622: PetscStageLogGetEventRegLog(stageLog,&eventRegLog);
623: if (!eventRegLog->eventInfo[event].collective) return(0);
624: PetscStageLogGetCurrent(stageLog,&stage);
625: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
626: if (eventLog->eventInfo[event].depth > 0) return(0);
628: PetscTimeSubtract(&time);
629: MPI_Barrier(comm);
630: PetscTimeAdd(&time);
631: eventLog->eventInfo[event].syncTime += time;
632: return(0);
633: }
635: PetscErrorCode PetscLogEventBeginDefault(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
636: {
637: PetscStageLog stageLog;
638: PetscEventPerfLog eventLog = NULL;
639: int stage;
640: PetscErrorCode ierr;
643: PetscLogGetStageLog(&stageLog);
644: PetscStageLogGetCurrent(stageLog,&stage);
645: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
646: /* Synchronization */
647: PetscLogEventSynchronize(event,PetscObjectComm(o1));
648: /* Check for double counting */
649: eventLog->eventInfo[event].depth++;
650: if (eventLog->eventInfo[event].depth > 1) return(0);
651: /* Log the performance info */
652: eventLog->eventInfo[event].count++;
653: eventLog->eventInfo[event].timeTmp = 0.0;
654: PetscTimeSubtract(&eventLog->eventInfo[event].timeTmp);
655: eventLog->eventInfo[event].flopsTmp = -petsc_TotalFlops;
656: eventLog->eventInfo[event].numMessages -= petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
657: eventLog->eventInfo[event].messageLength -= petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
658: eventLog->eventInfo[event].numReductions -= petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
659: if (PetscLogMemory) {
660: PetscLogDouble usage;
661: PetscMemoryGetCurrentUsage(&usage);
662: eventLog->eventInfo[event].memIncrease -= usage;
663: PetscMallocGetCurrentUsage(&usage);
664: eventLog->eventInfo[event].mallocSpace -= usage;
665: PetscMallocGetMaximumUsage(&usage);
666: eventLog->eventInfo[event].mallocIncrease -= usage;
667: PetscMallocPushMaximumUsage((int)event);
668: }
669: #if defined(PETSC_HAVE_DEVICE)
670: eventLog->eventInfo[event].CpuToGpuCount -= petsc_ctog_ct;
671: eventLog->eventInfo[event].GpuToCpuCount -= petsc_gtoc_ct;
672: eventLog->eventInfo[event].CpuToGpuSize -= petsc_ctog_sz;
673: eventLog->eventInfo[event].GpuToCpuSize -= petsc_gtoc_sz;
674: eventLog->eventInfo[event].GpuFlops -= petsc_gflops;
675: eventLog->eventInfo[event].GpuTime -= petsc_gtime;
676: #endif
677: return(0);
678: }
680: PetscErrorCode PetscLogEventEndDefault(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
681: {
682: PetscStageLog stageLog;
683: PetscEventPerfLog eventLog = NULL;
684: int stage;
685: PetscErrorCode ierr;
688: PetscLogGetStageLog(&stageLog);
689: PetscStageLogGetCurrent(stageLog,&stage);
690: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
691: /* Check for double counting */
692: eventLog->eventInfo[event].depth--;
693: if (eventLog->eventInfo[event].depth > 0) return(0);
694: else if (eventLog->eventInfo[event].depth < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Logging event had unbalanced begin/end pairs");
695: /* Log performance info */
696: PetscTimeAdd(&eventLog->eventInfo[event].timeTmp);
697: eventLog->eventInfo[event].time += eventLog->eventInfo[event].timeTmp;
698: eventLog->eventInfo[event].time2 += eventLog->eventInfo[event].timeTmp*eventLog->eventInfo[event].timeTmp;
699: eventLog->eventInfo[event].flopsTmp += petsc_TotalFlops;
700: eventLog->eventInfo[event].flops += eventLog->eventInfo[event].flopsTmp;
701: eventLog->eventInfo[event].flops2 += eventLog->eventInfo[event].flopsTmp*eventLog->eventInfo[event].flopsTmp;
702: eventLog->eventInfo[event].numMessages += petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
703: eventLog->eventInfo[event].messageLength += petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
704: eventLog->eventInfo[event].numReductions += petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
705: if (PetscLogMemory) {
706: PetscLogDouble usage,musage;
707: PetscMemoryGetCurrentUsage(&usage);
708: eventLog->eventInfo[event].memIncrease += usage;
709: PetscMallocGetCurrentUsage(&usage);
710: eventLog->eventInfo[event].mallocSpace += usage;
711: PetscMallocPopMaximumUsage((int)event,&musage);
712: eventLog->eventInfo[event].mallocIncreaseEvent = PetscMax(musage-usage,eventLog->eventInfo[event].mallocIncreaseEvent);
713: PetscMallocGetMaximumUsage(&usage);
714: eventLog->eventInfo[event].mallocIncrease += usage;
715: }
716: #if defined(PETSC_HAVE_DEVICE)
717: eventLog->eventInfo[event].CpuToGpuCount += petsc_ctog_ct;
718: eventLog->eventInfo[event].GpuToCpuCount += petsc_gtoc_ct;
719: eventLog->eventInfo[event].CpuToGpuSize += petsc_ctog_sz;
720: eventLog->eventInfo[event].GpuToCpuSize += petsc_gtoc_sz;
721: eventLog->eventInfo[event].GpuFlops += petsc_gflops;
722: eventLog->eventInfo[event].GpuTime += petsc_gtime;
723: #endif
724: return(0);
725: }
727: PetscErrorCode PetscLogEventBeginComplete(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
728: {
729: PetscStageLog stageLog;
730: PetscEventRegLog eventRegLog;
731: PetscEventPerfLog eventPerfLog = NULL;
732: Action *tmpAction;
733: PetscLogDouble start,end;
734: PetscLogDouble curTime;
735: int stage;
736: PetscErrorCode ierr;
739: /* Dynamically enlarge logging structures */
740: if (petsc_numActions >= petsc_maxActions) {
741: PetscTime(&start);
742: PetscCalloc1(petsc_maxActions*2,&tmpAction);
743: PetscArraycpy(tmpAction,petsc_actions,petsc_maxActions);
744: PetscFree(petsc_actions);
746: petsc_actions = tmpAction;
747: petsc_maxActions *= 2;
748: PetscTime(&end);
749: petsc_BaseTime += (end - start);
750: }
751: /* Record the event */
752: PetscLogGetStageLog(&stageLog);
753: PetscStageLogGetCurrent(stageLog,&stage);
754: PetscStageLogGetEventRegLog(stageLog,&eventRegLog);
755: PetscStageLogGetEventPerfLog(stageLog,stage,&eventPerfLog);
756: PetscTime(&curTime);
757: if (petsc_logActions) {
758: petsc_actions[petsc_numActions].time = curTime - petsc_BaseTime;
759: petsc_actions[petsc_numActions].action = ACTIONBEGIN;
760: petsc_actions[petsc_numActions].event = event;
761: petsc_actions[petsc_numActions].classid = eventRegLog->eventInfo[event].classid;
762: if (o1) petsc_actions[petsc_numActions].id1 = o1->id;
763: else petsc_actions[petsc_numActions].id1 = -1;
764: if (o2) petsc_actions[petsc_numActions].id2 = o2->id;
765: else petsc_actions[petsc_numActions].id2 = -1;
766: if (o3) petsc_actions[petsc_numActions].id3 = o3->id;
767: else petsc_actions[petsc_numActions].id3 = -1;
768: petsc_actions[petsc_numActions].flops = petsc_TotalFlops;
770: PetscMallocGetCurrentUsage(&petsc_actions[petsc_numActions].mem);
771: PetscMallocGetMaximumUsage(&petsc_actions[petsc_numActions].maxmem);
772: petsc_numActions++;
773: }
774: /* Check for double counting */
775: eventPerfLog->eventInfo[event].depth++;
776: if (eventPerfLog->eventInfo[event].depth > 1) return(0);
777: /* Log the performance info */
778: eventPerfLog->eventInfo[event].count++;
779: eventPerfLog->eventInfo[event].time -= curTime;
780: eventPerfLog->eventInfo[event].flops -= petsc_TotalFlops;
781: eventPerfLog->eventInfo[event].numMessages -= petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
782: eventPerfLog->eventInfo[event].messageLength -= petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
783: eventPerfLog->eventInfo[event].numReductions -= petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
784: return(0);
785: }
787: PetscErrorCode PetscLogEventEndComplete(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
788: {
789: PetscStageLog stageLog;
790: PetscEventRegLog eventRegLog;
791: PetscEventPerfLog eventPerfLog = NULL;
792: Action *tmpAction;
793: PetscLogDouble start,end;
794: PetscLogDouble curTime;
795: int stage;
796: PetscErrorCode ierr;
799: /* Dynamically enlarge logging structures */
800: if (petsc_numActions >= petsc_maxActions) {
801: PetscTime(&start);
802: PetscCalloc1(petsc_maxActions*2,&tmpAction);
803: PetscArraycpy(tmpAction,petsc_actions,petsc_maxActions);
804: PetscFree(petsc_actions);
806: petsc_actions = tmpAction;
807: petsc_maxActions *= 2;
808: PetscTime(&end);
809: petsc_BaseTime += (end - start);
810: }
811: /* Record the event */
812: PetscLogGetStageLog(&stageLog);
813: PetscStageLogGetCurrent(stageLog,&stage);
814: PetscStageLogGetEventRegLog(stageLog,&eventRegLog);
815: PetscStageLogGetEventPerfLog(stageLog,stage,&eventPerfLog);
816: PetscTime(&curTime);
817: if (petsc_logActions) {
818: petsc_actions[petsc_numActions].time = curTime - petsc_BaseTime;
819: petsc_actions[petsc_numActions].action = ACTIONEND;
820: petsc_actions[petsc_numActions].event = event;
821: petsc_actions[petsc_numActions].classid = eventRegLog->eventInfo[event].classid;
822: if (o1) petsc_actions[petsc_numActions].id1 = o1->id;
823: else petsc_actions[petsc_numActions].id1 = -1;
824: if (o2) petsc_actions[petsc_numActions].id2 = o2->id;
825: else petsc_actions[petsc_numActions].id2 = -1;
826: if (o3) petsc_actions[petsc_numActions].id3 = o3->id;
827: else petsc_actions[petsc_numActions].id3 = -1;
828: petsc_actions[petsc_numActions].flops = petsc_TotalFlops;
830: PetscMallocGetCurrentUsage(&petsc_actions[petsc_numActions].mem);
831: PetscMallocGetMaximumUsage(&petsc_actions[petsc_numActions].maxmem);
832: petsc_numActions++;
833: }
834: /* Check for double counting */
835: eventPerfLog->eventInfo[event].depth--;
836: if (eventPerfLog->eventInfo[event].depth > 0) return(0);
837: else if (eventPerfLog->eventInfo[event].depth < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Logging event had unbalanced begin/end pairs");
838: /* Log the performance info */
839: eventPerfLog->eventInfo[event].count++;
840: eventPerfLog->eventInfo[event].time += curTime;
841: eventPerfLog->eventInfo[event].flops += petsc_TotalFlops;
842: eventPerfLog->eventInfo[event].numMessages += petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct;
843: eventPerfLog->eventInfo[event].messageLength += petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len;
844: eventPerfLog->eventInfo[event].numReductions += petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct;
845: return(0);
846: }
848: PetscErrorCode PetscLogEventBeginTrace(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
849: {
850: PetscStageLog stageLog;
851: PetscEventRegLog eventRegLog;
852: PetscEventPerfLog eventPerfLog = NULL;
853: PetscLogDouble cur_time;
854: PetscMPIInt rank;
855: int stage,err;
856: PetscErrorCode ierr;
859: if (!petsc_tracetime) PetscTime(&petsc_tracetime);
861: petsc_tracelevel++;
862: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
863: PetscLogGetStageLog(&stageLog);
864: PetscStageLogGetCurrent(stageLog,&stage);
865: PetscStageLogGetEventRegLog(stageLog,&eventRegLog);
866: PetscStageLogGetEventPerfLog(stageLog,stage,&eventPerfLog);
867: /* Check for double counting */
868: eventPerfLog->eventInfo[event].depth++;
869: if (eventPerfLog->eventInfo[event].depth > 1) return(0);
870: /* Log performance info */
871: PetscTime(&cur_time);
872: PetscFPrintf(PETSC_COMM_SELF,petsc_tracefile,"%s[%d] %g Event begin: %s\n",petsc_tracespace,rank,cur_time-petsc_tracetime,eventRegLog->eventInfo[event].name);
873: PetscStrncpy(petsc_tracespace,petsc_traceblanks,2*petsc_tracelevel);
875: petsc_tracespace[2*petsc_tracelevel] = 0;
877: err = fflush(petsc_tracefile);
878: if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
879: return(0);
880: }
882: PetscErrorCode PetscLogEventEndTrace(PetscLogEvent event,int t,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)
883: {
884: PetscStageLog stageLog;
885: PetscEventRegLog eventRegLog;
886: PetscEventPerfLog eventPerfLog = NULL;
887: PetscLogDouble cur_time;
888: int stage,err;
889: PetscMPIInt rank;
890: PetscErrorCode ierr;
893: petsc_tracelevel--;
894: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
895: PetscLogGetStageLog(&stageLog);
896: PetscStageLogGetCurrent(stageLog,&stage);
897: PetscStageLogGetEventRegLog(stageLog,&eventRegLog);
898: PetscStageLogGetEventPerfLog(stageLog,stage,&eventPerfLog);
899: /* Check for double counting */
900: eventPerfLog->eventInfo[event].depth--;
901: if (eventPerfLog->eventInfo[event].depth > 0) return(0);
902: 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");
904: /* Log performance info */
905: if (petsc_tracelevel) {
906: PetscStrncpy(petsc_tracespace,petsc_traceblanks,2*petsc_tracelevel);
907: }
908: petsc_tracespace[2*petsc_tracelevel] = 0;
909: PetscTime(&cur_time);
910: PetscFPrintf(PETSC_COMM_SELF,petsc_tracefile,"%s[%d] %g Event end: %s\n",petsc_tracespace,rank,cur_time-petsc_tracetime,eventRegLog->eventInfo[event].name);
911: err = fflush(petsc_tracefile);
912: if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
913: return(0);
914: }
916: /*@C
917: PetscLogEventSetDof - Set the nth number of degrees of freedom associated with this event
919: Not Collective
921: Input Parameters:
922: + event - The event id to log
923: . n - The dof index, in [0, 8)
924: - dof - The number of dofs
926: Database Options:
927: . -log_view - Activates log summary
929: Note: This is to enable logging of convergence
931: Level: developer
933: .seealso: PetscLogEventSetError(), PetscEventRegLogRegister(), PetscStageLogGetEventLog()
934: @*/
935: PetscErrorCode PetscLogEventSetDof(PetscLogEvent event, PetscInt n, PetscLogDouble dof)
936: {
937: PetscStageLog stageLog;
938: PetscEventPerfLog eventLog = NULL;
939: int stage;
940: PetscErrorCode ierr;
943: if ((n < 0) || (n > 7)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Error index %D is not in [0, 8)", n);
944: PetscLogGetStageLog(&stageLog);
945: PetscStageLogGetCurrent(stageLog,&stage);
946: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
947: eventLog->eventInfo[event].dof[n] = dof;
948: return(0);
949: }
951: /*@C
952: PetscLogEventSetError - Set the nth error associated with this event
954: Not Collective
956: Input Parameters:
957: + event - The event id to log
958: . n - The error index, in [0, 8)
959: - error - The error
961: Database Options:
962: . -log_view - Activates log summary
964: Note: This is to enable logging of convergence, and enable users to interpret the errors as they wish. For example,
965: as different norms, or as errors for different fields
967: Level: developer
969: .seealso: PetscLogEventSetDof(), PetscEventRegLogRegister(), PetscStageLogGetEventLog()
970: @*/
971: PetscErrorCode PetscLogEventSetError(PetscLogEvent event, PetscInt n, PetscLogDouble error)
972: {
973: PetscStageLog stageLog;
974: PetscEventPerfLog eventLog = NULL;
975: int stage;
976: PetscErrorCode ierr;
979: if ((n < 0) || (n > 7)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Error index %D is not in [0, 8)", n);
980: PetscLogGetStageLog(&stageLog);
981: PetscStageLogGetCurrent(stageLog,&stage);
982: PetscStageLogGetEventPerfLog(stageLog,stage,&eventLog);
983: eventLog->eventInfo[event].errors[n] = error;
984: return(0);
985: }