xref: /petsc/src/benchmarks/PLogEvent.c (revision a336c15037c72f93cd561f5a5e11e93175f2efd9)
1 #include <petscsys.h>
2 #include <petsctime.h>
3 
4 int main(int argc, char **argv)
5 {
6   PetscLogDouble x, y;
7   PetscLogEvent  e1;
8   PetscBool      flg;
9 
10   PetscCall(PetscInitialize(&argc, &argv, 0, 0));
11   PetscLogEventRegister("*DummyEvent", 0, &e1);
12   /* To take care of the paging effects */
13   PetscCall(PetscTime(&x));
14   PetscCall(PetscLogEventBegin(e1, &x, 0, 0, 0));
15   PetscCall(PetscLogEventEnd(e1, &x, 0, 0, 0));
16 
17   PetscCall(PetscTime(&x));
18   /* 10 Occurrences of the dummy event */
19   PetscCall(PetscLogEventBegin(e1, &x, 0, 0, 0));
20   PetscCall(PetscLogEventEnd(e1, &x, 0, 0, 0));
21   PetscCall(PetscLogEventBegin(e1, &x, &y, 0, 0));
22   PetscCall(PetscLogEventEnd(e1, &x, &y, 0, 0));
23   PetscCall(PetscLogEventBegin(e1, &y, 0, 0, 0));
24   PetscCall(PetscLogEventEnd(e1, &y, 0, 0, 0));
25   PetscCall(PetscLogEventBegin(e1, &x, 0, 0, 0));
26   PetscCall(PetscLogEventEnd(e1, &x, 0, 0, 0));
27   PetscCall(PetscLogEventBegin(e1, &x, &y, 0, 0));
28   PetscCall(PetscLogEventEnd(e1, &x, &y, 0, 0));
29   PetscCall(PetscLogEventBegin(e1, &y, 0, 0, 0));
30   PetscCall(PetscLogEventEnd(e1, &y, 0, 0, 0));
31   PetscCall(PetscLogEventBegin(e1, &x, 0, 0, 0));
32   PetscCall(PetscLogEventEnd(e1, &x, 0, 0, 0));
33   PetscCall(PetscLogEventBegin(e1, &x, &y, 0, 0));
34   PetscCall(PetscLogEventEnd(e1, &x, &y, 0, 0));
35   PetscCall(PetscLogEventBegin(e1, &y, 0, 0, 0));
36   PetscCall(PetscLogEventEnd(e1, &y, 0, 0, 0));
37   PetscCall(PetscLogEventBegin(e1, &x, &e1, 0, 0));
38   PetscCall(PetscLogEventEnd(e1, &x, &e1, 0, 0));
39 
40   PetscCall(PetscTime(&y));
41   fprintf(stderr, "%-15s : %e sec, with options : ", "PetscLogEvent", (y - x) / 10.0);
42 
43   PetscCall(PetscOptionsHasName(NULL, "-log", &flg));
44   if (flg) fprintf(stderr, "-log ");
45   PetscCall(PetscOptionsHasName(NULL, "-log_all", &flg));
46   if (flg) fprintf(stderr, "-log_all ");
47   PetscCall(PetscOptionsHasName(NULL, "-log_view", &flg));
48   if (flg) fprintf(stderr, "-log_view ");
49   PetscCall(PetscOptionsHasName(NULL, "-log_mpe", &flg));
50   if (flg) fprintf(stderr, "-log_mpe ");
51 
52   fprintf(stderr, "\n");
53 
54   PetscCall(PetscFinalize());
55   return 0;
56 }
57