Actual source code: ex3.c

  1: /*$Id: ex3.c,v 1.39 2001/03/23 23:21:03 balay Exp $*/

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

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

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

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

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

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

 46:   /* 
 47:      We disable the logging of an event.

 49:   */
 50:   PetscLogEventDeactivate(USER_EVENT);
 51:   PetscLogEventBegin(USER_EVENT,0,0,0,0);
 52:   PetscSleep(1);
 53:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

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

 63:   PetscFinalize();
 64:   return 0;
 65: }
 66: