PAPI
5.7.0.0
PAPI_get_virt_cyc.c
Go to the documentation of this file.
1
/******************************************************************************
2
* This is an example to show how to use low level function PAPI_get_virt_cyc *
3
* and PAPI_get_virt_usec. *
4
******************************************************************************/
5
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include "
papi.h
"
/* This needs to be included every time you use PAPI */
9
10
int
i
;
11
double
tmp
;
12
13
int
your_slow_code
()
14
{
15
16
for
(
i
=1;
i
<200000;
i
++)
17
{
18
tmp
= (
tmp
+
i
)/2;
19
}
20
return
0;
21
}
22
23
int
main
()
24
{
25
long
long
s
,s1, e, e1;
26
int
retval
;
27
28
29
/****************************************************************************
30
* This part initializes the library and compares the version number of the *
31
* header file, to the version of the library, if these don't match then it *
32
* is likely that PAPI won't work correctly.If there is an error, retval *
33
* keeps track of the version number. *
34
****************************************************************************/
35
36
if
((
retval
=
PAPI_library_init
(
PAPI_VER_CURRENT
)) !=
PAPI_VER_CURRENT
)
37
{
38
printf(
"Library initialization error! \n"
);
39
exit
(1);
40
}
41
42
/* Here you get initial cycles and time */
43
/* No error checking is done here because this function call is always
44
successful */
45
46
s
=
PAPI_get_virt_cyc
();
47
48
your_slow_code
();
49
50
/*Here you get final cycles and time */
51
e =
PAPI_get_virt_cyc
();
52
53
s1=
PAPI_get_virt_usec
();
54
55
your_slow_code
();
56
57
e1=
PAPI_get_virt_usec
();
58
59
printf(
"Virtual cycles : %lld\nVirtual time(ms): %lld\n"
,e-
s
,e1-s1);
60
61
/* clean up */
62
PAPI_shutdown
();
63
64
exit
(0);
65
}
66
your_slow_code
int your_slow_code()
Definition:
PAPI_get_virt_cyc.c:13
PAPI_get_virt_usec
long long PAPI_get_virt_usec(void)
Definition:
papi.c:6372
PAPI_get_virt_cyc
long long PAPI_get_virt_cyc(void)
Definition:
papi.c:6300
PAPI_VER_CURRENT
#define PAPI_VER_CURRENT
Definition:
fpapi.h:14
retval
int retval
Definition:
zero_fork.c:53
tmp
double tmp
Definition:
PAPI_get_virt_cyc.c:11
papi.h
Return codes and api definitions.
main
int main()
Definition:
PAPI_get_virt_cyc.c:23
PAPI_library_init
int PAPI_library_init(int version)
Definition:
papi.c:500
PAPI_shutdown
void PAPI_shutdown(void)
Definition:
papi.c:4461
s
double s
Definition:
byte_profile.c:36
i
int i
Definition:
PAPI_get_virt_cyc.c:10
exit
void exit()
src
examples
PAPI_get_virt_cyc.c
Generated on Wed Mar 27 2019 00:55:11 for PAPI by
1.8.15