Actual source code: ex3f.F

petsc-3.14.6 2021-03-30
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:       PetscClassId  classid
 30:       integer imax
 31:       PetscErrorCode ierr
 32:       parameter (imax = 10000)
 33:       PetscLogDouble onefp
 34:       parameter (onefp = 1.0d0)
 35:       PetscReal onereal,tenreal
 36:       parameter (onereal = 1.0, tenreal = 10.0)
 37:       PetscInt n
 38: !
 39: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 40: !                 Beginning of program
 41: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

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

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

124:       end


127: !
128: !/*TEST
129: !
130: !   test:
131: !
132: !TEST*/