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: #undef __FUNCT__
26: int main(int argc,char **argv)
27: {
28: int i,ierr,imax=10000,icount,USER_EVENT;
30: PetscInitialize(&argc,&argv,(char *)0,help);
32: /*
33: Create a new user-defined event.
34: - Note that PetscLogEventRegister() returns to the user a unique
35: integer event number, which should then be used for profiling
36: the event via PetscLogEventBegin() and PetscLogEventEnd().
37: - The user can also optionally log floating point operations
38: with the routine PetscLogFlops().
39: */
40: PetscLogEventRegister(&USER_EVENT,"User event",PETSC_VIEWER_COOKIE);
41: PetscLogEventBegin(USER_EVENT,0,0,0,0);
42: icount = 0;
43: for (i=0; i<imax; i++) icount++;
44: PetscLogFlops(imax);
45: PetscSleep(1);
46: PetscLogEventEnd(USER_EVENT,0,0,0,0);
48: /*
49: We disable the logging of an event.
51: */
52: PetscLogEventDeactivate(USER_EVENT);
53: PetscLogEventBegin(USER_EVENT,0,0,0,0);
54: PetscSleep(1);
55: PetscLogEventEnd(USER_EVENT,0,0,0,0);
57: /*
58: We next enable the logging of an event
59: */
60: PetscLogEventActivate(USER_EVENT);
61: PetscLogEventBegin(USER_EVENT,0,0,0,0);
62: PetscSleep(1);
63: PetscLogEventEnd(USER_EVENT,0,0,0,0);
65: PetscFinalize();
66: return 0;
67: }
68: