1

我有一个使用 PETSc 的应用程序。对于(接近)生产运行下的性能监控,我想记录少量的各种值。有些是由 PETSc 生成的,有些不是。

现在我想知道:如何读取时间值PetscEventPerfInfo并将其写入我的文件?我找不到关于 的文档条目PetscEventPerfInfo,所以我不确定我是否不应该以任何方式触摸它。

但是,我发现以下方法基本上揭示了结构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);
}

我有一个强烈的猜测,它只是eventInfo->time,但我绝对不确定是否可以保存阅读它,或者是否有一种“官方”方式可以从该结构中读取。

那么,如果我只是想将时间值读入变量中以供进一步使用,该怎么办?

4

1 回答 1

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().

于 2017-09-04T19:14:41.327 回答