Actual source code: ex3.c
1: /*$Id: ex3.c,v 1.39 2001/03/23 23:21:03 balay Exp $*/
3: static char help[] = "Augmenting PETSc profiling by add events.n
4: Run this program with one of then
5: following options to generate logging information: -log, -log_summary,n
6: -log_all. The PETSc routines automatically log event times and flops,n
7: so this monitoring is intended solely for users to employ in applicationn
8: codes. Note that the code must be compiled with the flag -DPETSC_USE_LOGn
9: (the default) to activate logging.nn";
11: /*T
12: Concepts: PetscLog^user-defined event profiling
13: Concepts: profiling^user-defined event
14: Concepts: PetscLog^activating/deactivating events for profiling
15: Concepts: profiling^activating/deactivating events
16: Processors: n
17: T*/
19: /*
20: Include "petsc.h" so that we can use PETSc profiling routines.
21: */
22: #include "petsc.h"
24: int main(int argc,char **argv)
25: {
26: int i,ierr,imax=10000,icount,USER_EVENT;
28: PetscInitialize(&argc,&argv,(char *)0,help);
30: /*
31: Create a new user-defined event.
32: - Note that PetscLogEventRegister() returns to the user a unique
33: integer event number, which should then be used for profiling
34: the event via PetscLogEventBegin() and PetscLogEventEnd().
35: - The user can also optionally log floating point operations
36: with the routine PetscLogFlops().
37: */
38: PetscLogEventRegister(&USER_EVENT,"User event","Red:");
39: PetscLogEventBegin(USER_EVENT,0,0,0,0);
40: icount = 0;
41: for (i=0; i<imax; i++) icount++;
42: PetscLogFlops(imax);
43: PetscSleep(1);
44: PetscLogEventEnd(USER_EVENT,0,0,0,0);
46: /*
47: We disable the logging of an event.
48: - Note that activation/deactivation of PETSc events and MPE
49: events is handled separately.
50: - Note that the user can activate/deactive both user-defined
51: events and predefined PETSc events.
52: */
53: PetscLogEventMPEDeactivate(USER_EVENT);
54: PetscLogEventDeactivate(USER_EVENT);
55: PetscLogEventBegin(USER_EVENT,0,0,0,0);
56: PetscSleep(1);
57: PetscLogEventEnd(USER_EVENT,0,0,0,0);
59: /*
60: We next enable the logging of an event
61: */
62: PetscLogEventMPEActivate(USER_EVENT);
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: