Actual source code: ex3.c
petsc-3.6.4 2016-04-12
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>
22: #include <petscviewer.h>
26: int main(int argc,char **argv)
27: {
29: int i,imax=10000,icount;
30: #if defined(PETSC_USE_LOG)
31: PetscLogEvent USER_EVENT,check_USER_EVENT;
32: #endif
34: PetscInitialize(&argc,&argv,(char*)0,help);
36: /*
37: Create a new user-defined event.
38: - Note that PetscLogEventRegister() returns to the user a unique
39: integer event number, which should then be used for profiling
40: the event via PetscLogEventBegin() and PetscLogEventEnd().
41: - The user can also optionally log floating point operations
42: with the routine PetscLogFlops().
43: */
44: #if defined(PETSC_USE_LOG)
45: PetscLogEventRegister("User event",PETSC_VIEWER_CLASSID,&USER_EVENT);
46: PetscLogEventGetId("User event",&check_USER_EVENT);
47: if (USER_EVENT != check_USER_EVENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Event Ids do not match");
48: #endif
49: PetscLogEventBegin(USER_EVENT,0,0,0,0);
51: icount = 0;
52: for (i=0; i<imax; i++) icount++;
53: PetscLogFlops(imax);
54: PetscSleep(1);
55: PetscLogEventEnd(USER_EVENT,0,0,0,0);
57: /*
58: We disable the logging of an event.
60: */
61: PetscLogEventDeactivate(USER_EVENT);
62: PetscLogEventBegin(USER_EVENT,0,0,0,0);
63: PetscSleep(1);
64: PetscLogEventEnd(USER_EVENT,0,0,0,0);
66: /*
67: We next enable the logging of an event
68: */
69: PetscLogEventActivate(USER_EVENT);
70: PetscLogEventBegin(USER_EVENT,0,0,0,0);
71: PetscSleep(1);
72: PetscLogEventEnd(USER_EVENT,0,0,0,0);
74: PetscFinalize();
75: return 0;
76: }