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