PETSc automatically logs object creation, times, and floating-point
counts for the library routines. Users can easily supplement
this information by monitoring their application codes as well.
The basic steps involved in logging a
user-defined portion of code, called an event, are shown in the
code fragment below:
#include "petsclog.h" int USER_EVENT; PLogEventRegister(&USER_EVENT,"User event name","Color:"); PLogEventBegin(USER_EVENT,0,0,0,0); /* application code segment to monitor */ PLogFlops(number of flops for this code segment); PLogEventEnd(USER_EVENT,0,0,0,0);One must register the event by calling PLogEventRegister(), which assigns a unique integer to identify the event for profiling purposes:
ierr = PLogEventRegister(int *e,char *string,char *color);Here string is a user-defined event name, and color is an optional user-defined event color (for use with Upshot/Nupshot logging); one should see the manual page for details. The argument returned in e should then be passed to the PLogEventBegin() and PLogEventEnd() routines.
Events are logged by using the pair
PLogEventBegin(int event,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4); PLogEventEnd(int event,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4);The four objects are the PETSc objects that are most closely associated with the event. For instance, in a matrix-vector product they would be the matrix and the two vectors. These objects can be omitted by specifying 0 for o1 - o4. The code between these two routine calls will be automatically timed and logged as part of the specified event.
The user can log the number of floating-point operations
for this segment of code by calling
PLogFlops(number of flops for this code segment);between the calls to PLogEventBegin() and PLogEventEnd(). This value will automatically be added to the global flop counter for the entire program.