PAPI
7.1.0.0
Loading...
Searching...
No Matches
high_level.c
Go to the documentation of this file.
1
/*****************************************************************************
2
* This example code shows how to use PAPI's High level functions. *
3
* Events to be recorded are determined via an environment variable *
4
* PAPI_EVENTS that lists comma separated events for any component. *
5
* If events are not specified via the environment variable PAPI_EVENTS, an *
6
* output with default events is generated after the run. If supported by *
7
* the respective machine the following default events are recorded: *
8
* perf::TASK-CLOCK *
9
* PAPI_TOT_INS *
10
* PAPI_TOT_CYC *
11
* PAPI_FP_INS *
12
* PAPI_FP_OPS or PAPI_DP_OPS or PAPI_SP_OPS *
13
******************************************************************************/
14
15
#include <stdio.h>
16
#include <stdlib.h>
17
#include "
papi.h
"
18
19
#define THRESHOLD 10000
20
#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n"
, retval,__FILE__,__LINE__); exit(retval); }
21
22
/* stupid codes to be monitored */
23
void
computation_mult
()
24
{
25
double
tmp
=1.0;
26
int
i
=1;
27
for
(
i
= 1;
i
<
THRESHOLD
;
i
++ )
28
{
29
tmp
=
tmp
*
i
;
30
}
31
}
32
33
/* stupid codes to be monitored */
34
void
computation_add
()
35
{
36
int
tmp
= 0;
37
int
i
=0;
38
39
for
(
i
= 0;
i
<
THRESHOLD
;
i
++ )
40
{
41
tmp
=
tmp
+
i
;
42
}
43
44
}
45
46
47
int
main
()
48
{
49
int
retval
;
50
char
errstring[
PAPI_MAX_STR_LEN
];
51
52
retval
=
PAPI_hl_region_begin
(
"computation_add"
);
53
if
(
retval
!=
PAPI_OK
)
54
ERROR_RETURN
(
retval
);
55
56
/* Your code goes here*/
57
computation_add
();
58
59
retval
=
PAPI_hl_read
(
"computation_add"
);
60
if
(
retval
!=
PAPI_OK
)
61
ERROR_RETURN
(
retval
);
62
63
/* Your code goes here*/
64
computation_add
();
65
66
retval
=
PAPI_hl_region_end
(
"computation_add"
);
67
if
(
retval
!=
PAPI_OK
)
68
ERROR_RETURN
(
retval
);
69
70
71
retval
=
PAPI_hl_region_begin
(
"computation_mult"
);
72
if
(
retval
!=
PAPI_OK
)
73
ERROR_RETURN
(
retval
);
74
75
/* Your code goes here*/
76
computation_mult
();
77
78
retval
=
PAPI_hl_region_end
(
"computation_mult"
);
79
if
(
retval
!=
PAPI_OK
)
80
ERROR_RETURN
(
retval
);
81
82
exit(0);
83
}
tmp
double tmp
Definition:
PAPI_get_virt_cyc.c:11
i
int i
Definition:
PAPI_get_virt_cyc.c:10
PAPI_hl_read
Read performance events inside of a region and store the difference to the corresponding beginning of...
PAPI_hl_region_begin
Read performance events at the beginning of a region.
PAPI_hl_region_end
Read performance events at the end of a region and store the difference to the corresponding beginnin...
PAPI_OK
#define PAPI_OK
Definition:
f90papi.h:73
PAPI_MAX_STR_LEN
#define PAPI_MAX_STR_LEN
Definition:
f90papi.h:77
computation_add
void computation_add()
Definition:
high_level.c:34
THRESHOLD
#define THRESHOLD
Definition:
high_level.c:19
ERROR_RETURN
#define ERROR_RETURN(retval)
Definition:
high_level.c:20
computation_mult
void computation_mult()
Definition:
high_level.c:23
main
int main()
Definition:
high_level.c:47
papi.h
Return codes and api definitions.
retval
int retval
Definition:
zero_fork.c:53
src
examples
high_level.c
Generated on Wed Dec 20 2023 18:12:51 for PAPI by
1.9.6