1*f8402805SBarry Smith! 2*f8402805SBarry Smith! 3*f8402805SBarry Smith! Description: Demonstrates how users can augment the PETSc profiling by 4*f8402805SBarry Smith! nserting their own event logging. 5*f8402805SBarry Smith! 6*f8402805SBarry Smith! ----------------------------------------------------------------------- 7*f8402805SBarry Smith 8*f8402805SBarry Smith program main 9*f8402805SBarry Smith#include <petsc/finclude/petscsys.h> 10*f8402805SBarry Smith#include <petsc/finclude/petsclog.h> 11*f8402805SBarry Smith use petscsys 12*f8402805SBarry Smith implicit none 13*f8402805SBarry Smith 14*f8402805SBarry Smith! 15*f8402805SBarry Smith! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 16*f8402805SBarry Smith! Variable declarations 17*f8402805SBarry Smith! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 18*f8402805SBarry Smith! 19*f8402805SBarry Smith PetscLogEvent USER_EVENT1,USER_EVENT2 20*f8402805SBarry Smith PetscLogEvent USER_EVENT3,USER_EVENT4 21*f8402805SBarry Smith PetscLogEvent USER_EVENT5,USER_EVENT6 22*f8402805SBarry Smith PetscLogEvent USER_EVENT7,USER_EVENT8 23*f8402805SBarry Smith PetscLogEvent USER_EVENT9 24*f8402805SBarry Smith PetscClassId classid 25*f8402805SBarry Smith integer imax 26*f8402805SBarry Smith PetscErrorCode ierr 27*f8402805SBarry Smith parameter (imax = 10000) 28*f8402805SBarry Smith PetscLogDouble onefp 29*f8402805SBarry Smith parameter (onefp = 1.0d0) 30*f8402805SBarry Smith PetscReal onereal,tenreal 31*f8402805SBarry Smith parameter (onereal = 1.0, tenreal = 10.0) 32*f8402805SBarry Smith PetscInt n 33*f8402805SBarry Smith! 34*f8402805SBarry Smith! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 35*f8402805SBarry Smith! Beginning of program 36*f8402805SBarry Smith! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 37*f8402805SBarry Smith 38*f8402805SBarry Smith PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr)) 39*f8402805SBarry Smith 40*f8402805SBarry Smith! 41*f8402805SBarry Smith! Create a new user-defined event. 42*f8402805SBarry Smith! - Note that PetscLogEventRegister() returns to the user a unique 43*f8402805SBarry Smith! integer event number, which should then be used for profiling 44*f8402805SBarry Smith! the event via PetscLogEventBegin() and PetscLogEventEnd(). 45*f8402805SBarry Smith! - The user can also optionally log floating point operations 46*f8402805SBarry Smith! with the routine PetscLogFlops(). 47*f8402805SBarry Smith! 48*f8402805SBarry Smith classid = 0 49*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 1',classid,USER_EVENT1,ierr)) 50*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 2',classid,USER_EVENT2,ierr)) 51*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 3',classid,USER_EVENT3,ierr)) 52*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 4',classid,USER_EVENT4,ierr)) 53*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 5',classid,USER_EVENT5,ierr)) 54*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 6',classid,USER_EVENT6,ierr)) 55*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 7',classid,USER_EVENT7,ierr)) 56*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 8',classid,USER_EVENT8,ierr)) 57*f8402805SBarry Smith PetscCallA(PetscLogEventRegister('Event 9',classid,USER_EVENT9,ierr)) 58*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT1,ierr)) 59*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 60*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 61*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT1,ierr)) 62*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT2,ierr)) 63*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 64*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 65*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT2,ierr)) 66*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT3,ierr)) 67*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 68*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 69*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT3,ierr)) 70*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT4,ierr)) 71*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 72*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 73*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT4,ierr)) 74*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT5,ierr)) 75*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 76*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 77*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT5,ierr)) 78*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT6,ierr)) 79*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 80*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 81*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT6,ierr)) 82*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT7,ierr)) 83*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 84*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 85*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT7,ierr)) 86*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT8,ierr)) 87*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 88*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 89*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT8,ierr)) 90*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT9,ierr)) 91*f8402805SBarry Smith PetscCallA(PetscLogFlops(imax*onefp,ierr)) 92*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 93*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT9,ierr)) 94*f8402805SBarry Smith! 95*f8402805SBarry Smith! We disable the logging of an event. 96*f8402805SBarry Smith! - Note that the user can activate/deactive both user-defined 97*f8402805SBarry Smith! events and predefined PETSc events. 98*f8402805SBarry Smith! 99*f8402805SBarry Smith PetscCallA(PetscLogEventDeactivate(USER_EVENT1,ierr)) 100*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT1,ierr)) 101*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 102*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT1,ierr)) 103*f8402805SBarry Smith! 104*f8402805SBarry Smith! We next enable the logging of an event 105*f8402805SBarry Smith! 106*f8402805SBarry Smith PetscCallA(PetscLogEventActivate(USER_EVENT1,ierr)) 107*f8402805SBarry Smith PetscCallA(PetscLogEventBegin(USER_EVENT1,ierr)) 108*f8402805SBarry Smith PetscCallA(PetscSleep(onereal,ierr)) 109*f8402805SBarry Smith PetscCallA(PetscLogEventEnd(USER_EVENT1,ierr)) 110*f8402805SBarry Smith 111*f8402805SBarry Smith PetscCallA(PetscInfo('PETSc info message\n'//'Another line\n',ierr)) 112*f8402805SBarry Smith PetscCallA(PetscOptionsAllUsed(PETSC_NULL_OPTIONS,n,ierr)); 113*f8402805SBarry Smith PetscCallA(PetscFinalize(ierr)) 114*f8402805SBarry Smith 115*f8402805SBarry Smith end 116*f8402805SBarry Smith 117*f8402805SBarry Smith! 118*f8402805SBarry Smith!/*TEST 119*f8402805SBarry Smith! 120*f8402805SBarry Smith! test: 121*f8402805SBarry Smith! 122*f8402805SBarry Smith!TEST*/ 123