Actual source code: ex3.c

petsc-master 2019-03-24
Report Typos and Errors

  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_view,\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.\n\n";

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



 19: /*
 20:   Include "petscsys.h" so that we can use PETSc profiling routines.
 21: */
 22:  #include <petscsys.h>
 23:  #include <petscviewer.h>

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

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

 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",PETSC_VIEWER_CLASSID,&USER_EVENT);
 42:   PetscLogEventGetId("User event",&check_USER_EVENT);
 43:   if (USER_EVENT != check_USER_EVENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Event Ids do not match");
 44:   PetscLogEventBegin(USER_EVENT,0,0,0,0);

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

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

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

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

 69:   PetscFinalize();
 70:   return ierr;
 71: }



 75: /*TEST

 77:    build:
 78:      requires: define(PETSC_USE_LOG)

 80:    test:

 82: TEST*/