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: ! -----------------------------------------------------------------------

      8:       program main
      9: #include <petsc/finclude/petscsys.h>
     10: #include <petsc/finclude/petsclog.h>
     11:       use petscsys
     12:       implicit none

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

     38:       PetscCallA(PetscInitialize(ierr))

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

    111:       PetscCallA(PetscInfo('PETSc info message\n'//'Another line\n',ierr))
    112:       PetscCallA(PetscOptionsAllUsed(PETSC_NULL_OPTIONS,n,ierr));
    113:       PetscCallA(PetscFinalize(ierr))

    115:       end

    117: !
    118: !/*TEST
    119: !
    120: !   test:
    121: !
    122: !TEST*/