Actual source code: ex3.c
petsc-3.3-p7 2013-05-11
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_summary,\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. Note that the code must be compiled with the flag -DPETSC_USE_LOG\n\
8: (the default) to activate logging.\n\n";
10: /*T
11: Concepts: PetscLog^user-defined event profiling
12: Concepts: profiling^user-defined event
13: Concepts: PetscLog^activating/deactivating events for profiling
14: Concepts: profiling^activating/deactivating events
15: Processors: n
16: T*/
18: /*
19: Include "petscsys.h" so that we can use PETSc profiling routines.
20: */
21: #include <petscsys.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;
31: #endif
33: PetscInitialize(&argc,&argv,(char *)0,help);
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: PetscLogEventRegister("User event",PETSC_VIEWER_CLASSID,&USER_EVENT);
44: PetscLogEventBegin(USER_EVENT,0,0,0,0);
45: icount = 0;
46: for (i=0; i<imax; i++) icount++;
47: PetscLogFlops(imax);
48: PetscSleep(1);
49: PetscLogEventEnd(USER_EVENT,0,0,0,0);
51: /*
52: We disable the logging of an event.
54: */
55: PetscLogEventDeactivate(USER_EVENT);
56: PetscLogEventBegin(USER_EVENT,0,0,0,0);
57: PetscSleep(1);
58: PetscLogEventEnd(USER_EVENT,0,0,0,0);
60: /*
61: We next enable the logging of an event
62: */
63: PetscLogEventActivate(USER_EVENT);
64: PetscLogEventBegin(USER_EVENT,0,0,0,0);
65: PetscSleep(1);
66: PetscLogEventEnd(USER_EVENT,0,0,0,0);
68: PetscFinalize();
69: return 0;
70: }
71: