Actual source code: ex3.c

  2: static char help[] = "Augmenting PETSc profiling by add events.\n\
  3: Run this program with one of the\n\
  4: following options to generate logging information:  -log, -log_summary,\n\
  5: -log_all.  The PETSc routines automatically log event times and flops,\n\
  6: so this monitoring is intended solely for users to employ in application\n\
  7: codes.  Note that the code must be compiled with the flag -DPETSC_USE_LOG\n\
  8: (the default) to activate logging.\n\n";

 10: /*T
 11:    Concepts: PetscLog^user-defined event profiling
 12:    Concepts: profiling^user-defined event
 13:    Concepts: PetscLog^activating/deactivating events for profiling
 14:    Concepts: profiling^activating/deactivating events
 15:    Processors: n
 16: T*/

 18: /* 
 19:   Include "petsc.h" so that we can use PETSc profiling routines.
 20: */
 21:  #include petsc.h

 25: int main(int argc,char **argv)
 26: {
 28:   int            i,imax=10000,icount;
 29:   PetscEvent     USER_EVENT;

 31:   PetscInitialize(&argc,&argv,(char *)0,help);

 33:   /* 
 34:      Create a new user-defined event.
 35:       - Note that PetscLogEventRegister() returns to the user a unique
 36:         integer event number, which should then be used for profiling
 37:         the event via PetscLogEventBegin() and PetscLogEventEnd().
 38:       - The user can also optionally log floating point operations
 39:         with the routine PetscLogFlops().
 40:   */
 41:   PetscLogEventRegister(&USER_EVENT,"User event",PETSC_VIEWER_COOKIE);
 42:   PetscLogEventBegin(USER_EVENT,0,0,0,0);
 43:   icount = 0;
 44:   for (i=0; i<imax; i++) icount++;
 45:   PetscLogFlops(imax);
 46:   PetscSleep(1);
 47:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

 49:   /* 
 50:      We disable the logging of an event.

 52:   */
 53:   PetscLogEventDeactivate(USER_EVENT);
 54:   PetscLogEventBegin(USER_EVENT,0,0,0,0);
 55:   PetscSleep(1);
 56:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

 58:   /* 
 59:      We next enable the logging of an event
 60:   */
 61:   PetscLogEventActivate(USER_EVENT);
 62:   PetscLogEventBegin(USER_EVENT,0,0,0,0);
 63:   PetscSleep(1);
 64:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

 66:   PetscFinalize();
 67:   return 0;
 68: }
 69: