Actual source code: ex3f.F

petsc-3.9.4 2018-09-11
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:       PetscInt n
 37: !
 38: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 39: !                 Beginning of program
 40: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

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

118:       call PetscInfo('PETSc info message\n'//'Another line\n',ierr)
119:       call PetscOptionsAllUsed(PETSC_NULL_OPTIONS,n,ierr);
120:       call PetscFinalize(ierr)

122:       end


125: !
126: !/*TEST
127: !
128: !   test:
129: !
130: !TEST*/