Actual source code: ex3.c
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: /*
10: Include "petscsys.h" so that we can use PETSc profiling routines.
11: */
12: #include <petscsys.h>
13: #include <petscviewer.h>
15: int main(int argc, char **argv)
16: {
17: PetscMPIInt rank;
18: int i, imax = 10000, icount;
19: PetscLogEvent USER_EVENT, check_USER_EVENT;
22: PetscInitialize(&argc, &argv, NULL, help);
24: /*
25: Create a new user-defined event.
26: - Note that PetscLogEventRegister() returns to the user a unique
27: integer event number, which should then be used for profiling
28: the event via PetscLogEventBegin() and PetscLogEventEnd().
29: - The user can also optionally log floating point operations
30: with the routine PetscLogFlops().
31: */
32: PetscLogEventRegister("User event", PETSC_VIEWER_CLASSID, &USER_EVENT);
33: PetscLogEventGetId("User event", &check_USER_EVENT);
36: PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0);
37: icount = 0;
38: for (i = 0; i < imax; i++) icount++;
39: PetscLogFlops(imax);
40: PetscSleep(0.5);
41: PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0);
43: /*
44: We disable the logging of an event.
46: */
47: PetscLogEventDeactivate(USER_EVENT);
48: PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0);
49: PetscSleep(0.5);
50: PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0);
52: /*
53: We next enable the logging of an event
54: */
55: PetscLogEventActivate(USER_EVENT);
56: PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0);
57: PetscSleep(0.5);
58: PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0);
60: /*
61: We test event logging imbalance
62: */
63: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
64: if (rank == 0) PetscSleep(0.5);
65: PetscLogEventSync(USER_EVENT, PETSC_COMM_WORLD);
66: PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0);
67: MPI_Barrier(PETSC_COMM_WORLD);
68: PetscSleep(0.5);
69: PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0);
71: PetscFinalize();
72: return 0;
73: }
75: /*TEST
77: build:
78: requires: defined(PETSC_USE_LOG)
80: test:
82: TEST*/