Date: 2013-07-02T14:39:25+00:00

Actual source code: ex3.c
petsc-3.4.2 2013-07-02

      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 "petscsys.h" so that we can use PETSc profiling routines.
     20: */
     21: #include <petscsys.h>
     22: #include <petscviewer.h>

     26: int main(int argc,char **argv)
     27: {
     29:   int            i,imax=10000,icount;
     30: #if defined(PETSC_USE_LOG)
     31:   PetscLogEvent USER_EVENT;
     32: #endif

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

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

     47:   icount = 0;
     48:   for (i=0; i<imax; i++) icount++;
     49:   PetscLogFlops(imax);
     50:   PetscSleep(1);
     51:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

     53:   /*
     54:      We disable the logging of an event.

     56:   */
     57:   PetscLogEventDeactivate(USER_EVENT);
     58:   PetscLogEventBegin(USER_EVENT,0,0,0,0);
     59:   PetscSleep(1);
     60:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

     62:   /*
     63:      We next enable the logging of an event
     64:   */
     65:   PetscLogEventActivate(USER_EVENT);
     66:   PetscLogEventBegin(USER_EVENT,0,0,0,0);
     67:   PetscSleep(1);
     68:   PetscLogEventEnd(USER_EVENT,0,0,0,0);

     70:   PetscFinalize();
     71:   return 0;
     72: }