Actual source code: ex3f.F

petsc-master 2017-05-22
Report Typos and Errors
  1: !
  2: !
  3: !   Description: Demonstrates how users can augment the PETSc profiling by
  4: !                nserting their own event logging.
  5: !
  6: !/*T
  7: !   Concepts: PetscLog^user-defined event profiling (basic example);
  8: !   Concepts: PetscLog^activating/deactivating events for profiling (basic example);
  9: !   Processors: n
 10: !T*/
 11: ! -----------------------------------------------------------------------

 13:       program main
 14:  #include <petsc/finclude/petscsys.h>
 15:  #include <petsc/finclude/petsclog.h>
 16:       use petscsys
 17:       implicit none

 19: !
 20: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 21: !                   Variable declarations
 22: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 23: !
 24:       PetscLogEvent USER_EVENT1,USER_EVENT2
 25:       PetscLogEvent USER_EVENT3,USER_EVENT4
 26:       PetscLogEvent USER_EVENT5,USER_EVENT6
 27:       PetscLogEvent USER_EVENT7,USER_EVENT8
 28:       PetscLogEvent USER_EVENT9
 29:       integer imax
 30:       PetscErrorCode ierr
 31:       parameter (imax = 10000)
 32:       PetscLogDouble onefp
 33:       parameter (onefp = 1.0d0)
 34:       PetscReal onereal,tenreal
 35:       parameter (onereal = 1.0, tenreal = 10.0)
 36: !
 37: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 38: !                 Beginning of program
 39: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 41:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 42:       if (ierr .ne. 0) then
 43:          print*,'Unable to initialize PETSc'
 44:          stop
 45:       endif

 47: !
 48: !     Create a new user-defined event.
 49: !      - Note that PetscLogEventRegister() returns to the user a unique
 50: !        integer event number, which should then be used for profiling
 51: !        the event via PetscLogEventBegin() and PetscLogEventEnd().
 52: !      - The user can also optionally log floating point operations
 53: !        with the routine PetscLogFlops().
 54: !
 55:       call PetscLogEventRegister('Event 1',0,USER_EVENT1,ierr)
 56:       call PetscLogEventRegister('Event 2',0,USER_EVENT2,ierr)
 57:       call PetscLogEventRegister('Event 3',0,USER_EVENT3,ierr)
 58:       call PetscLogEventRegister('Event 4',0,USER_EVENT4,ierr)
 59:       call PetscLogEventRegister('Event 5',0,USER_EVENT5,ierr)
 60:       call PetscLogEventRegister('Event 6',0,USER_EVENT6,ierr)
 61:       call PetscLogEventRegister('Event 7',0,USER_EVENT7,ierr)
 62:       call PetscLogEventRegister('Event 8',0,USER_EVENT8,ierr)
 63:       call PetscLogEventRegister('Event 9',0,USER_EVENT9,ierr)
 64:       call PetscLogEventBegin(USER_EVENT1,ierr)
 65:       call PetscLogFlops(imax*onefp,ierr)
 66:       call PetscSleep(onereal,ierr)
 67:       call PetscLogEventEnd(USER_EVENT1,ierr)
 68:       call PetscLogEventBegin(USER_EVENT2,ierr)
 69:       call PetscLogFlops(imax*onefp,ierr)
 70:       call PetscSleep(onereal,ierr)
 71:       call PetscLogEventEnd(USER_EVENT2,ierr)
 72:       call PetscLogEventBegin(USER_EVENT3,ierr)
 73:       call PetscLogFlops(imax*onefp,ierr)
 74:       call PetscSleep(onereal,ierr)
 75:       call PetscLogEventEnd(USER_EVENT3,ierr)
 76:       call PetscLogEventBegin(USER_EVENT4,ierr)
 77:       call PetscLogFlops(imax*onefp,ierr)
 78:       call PetscSleep(onereal,ierr)
 79:       call PetscLogEventEnd(USER_EVENT4,ierr)
 80:       call PetscLogEventBegin(USER_EVENT5,ierr)
 81:       call PetscLogFlops(imax*onefp,ierr)
 82:       call PetscSleep(onereal,ierr)
 83:       call PetscLogEventEnd(USER_EVENT5,ierr)
 84:       call PetscLogEventBegin(USER_EVENT6,ierr)
 85:       call PetscLogFlops(imax*onefp,ierr)
 86:       call PetscSleep(onereal,ierr)
 87:       call PetscLogEventEnd(USER_EVENT6,ierr)
 88:       call PetscLogEventBegin(USER_EVENT7,ierr)
 89:       call PetscLogFlops(imax*onefp,ierr)
 90:       call PetscSleep(onereal,ierr)
 91:       call PetscLogEventEnd(USER_EVENT7,ierr)
 92:       call PetscLogEventBegin(USER_EVENT8,ierr)
 93:       call PetscLogFlops(imax*onefp,ierr)
 94:       call PetscSleep(onereal,ierr)
 95:       call PetscLogEventEnd(USER_EVENT8,ierr)
 96:       call PetscLogEventBegin(USER_EVENT9,ierr)
 97:       call PetscLogFlops(imax*onefp,ierr)
 98:       call PetscSleep(onereal,ierr)
 99:       call PetscLogEventEnd(USER_EVENT9,ierr)
100: !
101: !    We disable the logging of an event.
102: !      - Note that the user can activate/deactive both user-defined
103: !        events and predefined PETSc events.
104: !
105:       call PetscLogEventDeactivate(USER_EVENT1,ierr)
106:       call PetscLogEventBegin(USER_EVENT1,ierr)
107:       call PetscSleep(onereal,ierr)
108:       call PetscLogEventEnd(USER_EVENT1,ierr)
109: !
110: !    We next enable the logging of an event
111: !
112:       call PetscLogEventActivate(USER_EVENT1,ierr)
113:       call PetscLogEventBegin(USER_EVENT1,ierr)
114:       call PetscSleep(onereal,ierr)
115:       call PetscLogEventEnd(USER_EVENT1,ierr)

117:       call PetscInfo('PETSc info message\n'//'Another line\n',ierr)
118:       call PetscFinalize(ierr)

120:       end


123: !
124: !/*TEST
125: !
126: !   test:
127: !
128: !TEST*/