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