1

I have an application using PETSc. For performance monitoring under (near) production runs, I'd like to log a small number of various values. Some generated by PETSc, some not.

Now I wonder: How can I read the time value out of PetscEventPerfInfo to write it into my file? I can't find a documentation entry about PetscEventPerfInfo, so I'm not sure whether I'm not supposed to touch it in any way.

However, I found the following method which basically reveals the structure of PetscEventPerfInfo:

PetscErrorCode EventPerfInfoClear(PetscEventPerfInfo *eventInfo)
{
  PetscFunctionBegin;
  eventInfo->id            = -1;
  eventInfo->active        = PETSC_TRUE;
  eventInfo->visible       = PETSC_TRUE;
  eventInfo->depth         = 0;
  eventInfo->count         = 0;
  eventInfo->flops         = 0.0;
  eventInfo->flops2        = 0.0;
  eventInfo->flopsTmp      = 0.0;
  eventInfo->time          = 0.0;
  eventInfo->time2         = 0.0;
  eventInfo->timeTmp       = 0.0;
  eventInfo->numMessages   = 0.0;
  eventInfo->messageLength = 0.0;
  eventInfo->numReductions = 0.0;
  PetscFunctionReturn(0);
}

I have a strong guess that it's just eventInfo->time, but I'm absolutely not sure whether it's save to read it oder whether there's an "official" way to read from that structure.

So, what should I do if I just want to read the time value into a variable for further usage?

Michael
  • 7,407
  • 8
  • 41
  • 84

1 Answers1

1

Good news: there is an example of PETSC, src/dm/impls/plex/examples/tests/ex9.c which makes use of the field time of PetscEventPerfInfo to print performance-related logs!

The structure PetscEventPerfInfo is defined in petsc-3.7.6/include/petsclog.h. There are plenty of comments in the file. The field time is indeed defined as:

PetscLogDouble time, time2, timeTmp;   /* The time and time^2 taken for this event */

There are clues that time contains the execution time in eventlog.c. Indeed, in function PetscLogEventBeginComplete, there is a eventPerfLog->eventInfo[event].time -= curTime;, which matches the eventPerfLog->eventInfo[event].time += curTime; of PetscLogEventEndComplete().

Consequently, the value of the field time is interesting if an only if both PetscLogEventBeginComplete() and PetscLogEventEndComplete() have been called or both PetscLogEventBeginDefault() and PetscLogEventEndDefault().

francis
  • 9,525
  • 2
  • 25
  • 41