Actual source code: ex3f.F90

      1: !
      2: !
      3: !   Description: Demonstrates how users can augment the PETSc profiling by
      4: !                nserting their own event logging.
      5: !
      6: ! -----------------------------------------------------------------------
      7: #include <petsc/finclude/petscsys.h>
      8: #include <petsc/finclude/petsclog.h>
      9: program main
     10:   use petscsys
     11:   implicit none

     13: !
     14: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     15: !                   Variable declarations
     16: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     17: !
     18:   PetscLogEvent USER_EVENT1, USER_EVENT2
     19:   PetscLogEvent USER_EVENT3, USER_EVENT4
     20:   PetscLogEvent USER_EVENT5, USER_EVENT6
     21:   PetscLogEvent USER_EVENT7, USER_EVENT8
     22:   PetscLogEvent USER_EVENT9
     23:   PetscClassId classid
     24:   integer, parameter :: imax = 10000
     25:   PetscErrorCode ierr
     26:   PetscLogDouble, parameter :: onefp = 1.0
     27:   PetscReal, parameter :: onereal = 1.0
     28:   PetscInt n
     29: !
     30: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     31: !                 Beginning of program
     32: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

     34:   PetscCallA(PetscInitialize(ierr))

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

    107:   PetscCallA(PetscInfo('PETSc info message\n'//'Another line\n', ierr))
    108:   PetscCallA(PetscOptionsAllUsed(PETSC_NULL_OPTIONS, n, ierr))
    109:   PetscCallA(PetscFinalize(ierr))

    111: end

    113: !
    114: !/*TEST
    115: !
    116: !   test:
    117: !     output_file: output/empty.out
    118: !
    119: !TEST*/