PAPI
5.7.0.0
PAPI_set_domain.c
Go to the documentation of this file.
1
/*****************************************************************************
2
* This example shows how to use PAPI_set_domain *
3
*****************************************************************************/
4
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <sys/types.h>
8
#include <sys/stat.h>
9
#include <fcntl.h>
10
11
#include "
papi.h
"
/* This needs to be included every time you use PAPI */
12
13
#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
14
15
int
poorly_tuned_function
()
16
{
17
float
tmp
;
18
int
i
;
19
20
for
(
i
=1;
i
<2000;
i
++)
21
{
22
tmp
=(
tmp
+100)/
i
;
23
}
24
return
0;
25
}
26
27
int
main
()
28
{
29
30
int
num,
retval
,
EventSet
=
PAPI_NULL
;
31
long
long
values
[2];
32
PAPI_option_t
options
;
33
int
fd
;
34
35
36
/****************************************************************************
37
* This part initializes the library and compares the version number of the *
38
* header file, to the version of the library, if these don't match then it *
39
* is likely that PAPI won't work correctly.If there is an error, retval *
40
* keeps track of the version number. *
41
****************************************************************************/
42
43
if
((
retval
=
PAPI_library_init
(
PAPI_VER_CURRENT
)) !=
PAPI_VER_CURRENT
)
44
{
45
printf(
"Library initialization error! \n"
);
46
exit
(1);
47
}
48
49
/* Set the domain of this EventSet to counter user mode. The domain
50
will be valid for all the eventset created after this function call
51
unless you call PAPI_set_domain again */
52
if
((
retval
=
PAPI_set_domain
(
PAPI_DOM_USER
)) !=
PAPI_OK
)
53
ERROR_RETURN
(
retval
);
54
55
if
((
retval
=
PAPI_create_eventset
(&
EventSet
)) !=
PAPI_OK
)
56
ERROR_RETURN
(
retval
);
57
58
/* Add Total Instructions Executed event to the EventSet */
59
if
( (
retval
=
PAPI_add_event
(
EventSet
,
PAPI_TOT_INS
)) !=
PAPI_OK
)
60
ERROR_RETURN
(
retval
);
61
62
/* Add Total Cycles Executed event to the EventSet */
63
if
( (
retval
=
PAPI_add_event
(
EventSet
,
PAPI_TOT_CYC
)) !=
PAPI_OK
)
64
ERROR_RETURN
(
retval
);
65
66
/* Start counting */
67
if
((
retval
=
PAPI_start
(
EventSet
)) !=
PAPI_OK
)
68
ERROR_RETURN
(
retval
);
69
70
poorly_tuned_function
();
71
/* add some system calls */
72
fd
=
open
(
"/dev/zero"
, O_RDONLY);
73
if
(
fd
== -1)
74
{
75
perror(
"open(/dev/zero)"
);
76
exit
(1);
77
}
78
close
(
fd
);
79
80
81
/* Stop counting */
82
if
((
retval
=
PAPI_stop
(
EventSet
,
values
)) !=
PAPI_OK
)
83
ERROR_RETURN
(
retval
);
84
85
printf(
" Total instructions: %lld Total Cycles: %lld \n"
,
values
[0],
86
values
[1]);
87
88
/* Set the domain of this EventSet to counter user and kernel modes */
89
if
((
retval
=
PAPI_set_domain
(
PAPI_DOM_ALL
)) !=
PAPI_OK
)
90
ERROR_RETURN
(
retval
);
91
92
EventSet
=
PAPI_NULL
;
93
if
((
retval
=
PAPI_create_eventset
(&
EventSet
)) !=
PAPI_OK
)
94
ERROR_RETURN
(
retval
);
95
96
/* Add Total Instructions Executed to our EventSet */
97
if
( (
retval
=
PAPI_add_event
(
EventSet
,
PAPI_TOT_INS
)) !=
PAPI_OK
)
98
ERROR_RETURN
(
retval
);
99
100
/* Add Total Instructions Executed to our EventSet */
101
if
( (
retval
=
PAPI_add_event
(
EventSet
,
PAPI_TOT_CYC
)) !=
PAPI_OK
)
102
ERROR_RETURN
(
retval
);
103
/* Start counting */
104
if
((
retval
=
PAPI_start
(
EventSet
)) !=
PAPI_OK
)
105
ERROR_RETURN
(
retval
);
106
107
poorly_tuned_function
();
108
/* add some system calls */
109
fd
=
open
(
"/dev/zero"
, O_RDONLY);
110
if
(
fd
== -1)
111
{
112
perror(
"open(/dev/zero)"
);
113
exit
(1);
114
}
115
close
(
fd
);
116
117
/* Stop counting */
118
if
((
retval
=
PAPI_stop
(
EventSet
,
values
)) !=
PAPI_OK
)
119
ERROR_RETURN
(
retval
);
120
121
printf(
" Total instructions: %lld Total Cycles: %lld \n"
,
values
[0],
122
values
[1]);
123
124
/* clean up */
125
PAPI_shutdown
();
126
127
exit
(0);
128
}
PAPI_OK
#define PAPI_OK
Definition:
fpapi.h:105
PAPI_stop
int PAPI_stop(int EventSet, long long *values)
Definition:
papi.c:2314
close
int close(int fd)
Definition:
appio.c:175
PAPI_add_event
int PAPI_add_event(int EventSet, int EventCode)
Definition:
papi.c:1663
fd
int fd
Definition:
iozone.c:1291
PAPI_VER_CURRENT
#define PAPI_VER_CURRENT
Definition:
fpapi.h:14
EventSet
int EventSet
Definition:
cuda_ld_preload_example.c:27
retval
int retval
Definition:
zero_fork.c:53
PAPI_option_t
A pointer to the following is passed to PAPI_set/get_opt()
Definition:
papi.h:849
tmp
double tmp
Definition:
PAPI_get_virt_cyc.c:11
papi.h
Return codes and api definitions.
ERROR_RETURN
#define ERROR_RETURN(retval)
Definition:
PAPI_set_domain.c:13
poorly_tuned_function
int poorly_tuned_function()
Definition:
PAPI_set_domain.c:15
open
int open(const char *pathname, int flags, mode_t mode)
Definition:
appio.c:184
PAPI_library_init
int PAPI_library_init(int version)
Definition:
papi.c:500
PAPI_TOT_INS
#define PAPI_TOT_INS
Definition:
fpapi.h:186
PAPI_shutdown
void PAPI_shutdown(void)
Definition:
papi.c:4461
PAPI_DOM_USER
#define PAPI_DOM_USER
Definition:
fpapi.h:21
PAPI_NULL
#define PAPI_NULL
Definition:
fpapi.h:13
PAPI_create_eventset
int PAPI_create_eventset(int *EventSet)
Definition:
papi.c:1464
options
static options_t options
Definition:
papi_multiplex_cost.c:59
PAPI_set_domain
int PAPI_set_domain(int domain)
Definition:
papi.c:5688
PAPI_start
int PAPI_start(int EventSet)
Definition:
papi.c:2096
PAPI_TOT_CYC
#define PAPI_TOT_CYC
Definition:
fpapi.h:195
values
static long long values[NUM_EVENTS]
Definition:
init_fini.c:10
exit
void exit()
PAPI_DOM_ALL
#define PAPI_DOM_ALL
Definition:
fpapi.h:25
i
int i
Definition:
fileop.c:140
main
int main()
Definition:
PAPI_set_domain.c:27
src
examples
PAPI_set_domain.c
Generated on Wed Mar 27 2019 00:55:12 for PAPI by
1.8.15