Actual source code: ex3f.F

petsc-master 2016-09-27
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:       implicit none

 16: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 17: !                    Include files
 18: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 19: !
 20: !  The following include statements are required for using PetscLog Routines
 21: !
 22:  #include <petsc/finclude/petscsys.h>
 23:  #include <petsc/finclude/petsclog.h>
 24: !
 25: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 26: !                   Variable declarations
 27: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 28: !
 29:       PetscLogEvent USER_EVENT1,USER_EVENT2
 30:       PetscLogEvent USER_EVENT3,USER_EVENT4
 31:       PetscLogEvent USER_EVENT5,USER_EVENT6
 32:       PetscLogEvent USER_EVENT7,USER_EVENT8
 33:       PetscLogEvent USER_EVENT9
 34:       integer imax
 35:       PetscErrorCode ierr
 36:       parameter (imax = 10000)
 37:       PetscLogDouble onefp
 38:       parameter (onefp = 1.0d0)
 39:       PetscReal onereal,tenreal
 40:       parameter (onereal = 1.0, tenreal = 10.0)
 41: !
 42: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 43: !                 Beginning of program
 44: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

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

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

125:       end