Actual source code: ex3.c
petsc-3.8.4 2018-03-24
2: static char help[] = "Augmenting PETSc profiling by add events.\n\
3: Run this program with one of the\n\
4: following options to generate logging information: -log, -log_view,\n\
5: -log_all. The PETSc routines automatically log event times and flops,\n\
6: so this monitoring is intended solely for users to employ in application\n\
7: codes.\n\n";
9: /*T
10: Concepts: PetscLog^user-defined event profiling
11: Concepts: profiling^user-defined event
12: Concepts: PetscLog^activating/deactivating events for profiling
13: Concepts: profiling^activating/deactivating events
14: Processors: n
15: T*/
19: /*
20: Include "petscsys.h" so that we can use PETSc profiling routines.
21: */
22: #include <petscsys.h>
23: #include <petscviewer.h>
25: int main(int argc,char **argv)
26: {
28: int i,imax=10000,icount;
29: #if defined(PETSC_USE_LOG)
30: PetscLogEvent USER_EVENT,check_USER_EVENT;
31: #endif
33: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
35: /*
36: Create a new user-defined event.
37: - Note that PetscLogEventRegister() returns to the user a unique
38: integer event number, which should then be used for profiling
39: the event via PetscLogEventBegin() and PetscLogEventEnd().
40: - The user can also optionally log floating point operations
41: with the routine PetscLogFlops().
42: */
43: #if defined(PETSC_USE_LOG)
44: PetscLogEventRegister("User event",PETSC_VIEWER_CLASSID,&USER_EVENT);
45: PetscLogEventGetId("User event",&check_USER_EVENT);
46: if (USER_EVENT != check_USER_EVENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Event Ids do not match");
47: #endif
48: PetscLogEventBegin(USER_EVENT,0,0,0,0);
50: icount = 0;
51: for (i=0; i<imax; i++) icount++;
52: PetscLogFlops(imax);
53: PetscSleep(1);
54: PetscLogEventEnd(USER_EVENT,0,0,0,0);
56: /*
57: We disable the logging of an event.
59: */
60: PetscLogEventDeactivate(USER_EVENT);
61: PetscLogEventBegin(USER_EVENT,0,0,0,0);
62: PetscSleep(1);
63: PetscLogEventEnd(USER_EVENT,0,0,0,0);
65: /*
66: We next enable the logging of an event
67: */
68: PetscLogEventActivate(USER_EVENT);
69: PetscLogEventBegin(USER_EVENT,0,0,0,0);
70: PetscSleep(1);
71: PetscLogEventEnd(USER_EVENT,0,0,0,0);
73: PetscFinalize();
74: return ierr;
75: }
79: /*TEST
81: test:
83: TEST*/