PAPI 7.1.0.0
Loading...
Searching...
No Matches
PAPI_get_opt.c
Go to the documentation of this file.
1/*****************************************************************************
2 * This is an example using the low level function PAPI_get_opt to query the *
3 * option settings of the PAPI library or a specific eventset created by the *
4 * PAPI_create_eventset function. PAPI_set_opt is used on the otherhand to *
5 * set PAPI library or event set options. *
6 *****************************************************************************/
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include "papi.h" /* This needs to be included every time you use PAPI */
12#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
13
15{
16 float tmp;
17 int i;
18
19 for(i=1; i<2000; i++)
20 {
21 tmp=(tmp+100)/i;
22 }
23 return 0;
24}
25
26int main()
27{
28
29 int num, retval, EventSet = PAPI_NULL;
31 long long values[2];
32
33 /****************************************************************************
34 * This part initializes the library and compares the version number of the *
35 * header file, to the version of the library, if these don't match then it *
36 * is likely that PAPI won't work correctly.If there is an error, retval *
37 * keeps track of the version number. *
38 ****************************************************************************/
39
41 {
42 printf("Library initialization error! \n");
43 exit(1);
44 }
45
46 /*PAPI_get_opt returns a negative number if there is an error */
47
48 /* This call returns the maximum available hardware counters */
49 if((num = PAPI_get_opt(PAPI_MAX_HWCTRS,NULL)) <= 0)
50 ERROR_RETURN(num);
51
52
53 printf("This machine has %d counters.\n",num);
54
57
58 /* Set the domain of this EventSet to counter user and
59 kernel modes for this process. */
60
61 memset(&options,0x0,sizeof(options));
62
63 options.domain.eventset = EventSet;
64 /* Default domain is PAPI_DOM_USER */
65 options.domain.domain = PAPI_DOM_ALL;
66 /* this sets the options for the domain */
69 /* Add Total Instructions Executed event to the EventSet */
72
73 /* Add Total Cycles Executed event to the EventSet */
76
77 /* Start counting */
80
82
83 /* Stop counting */
86
87 printf(" Total instructions: %lld Total Cycles: %lld \n", values[0],
88 values[1]);
89
90 /* clean up */
92
93 exit(0);
94}
int poorly_tuned_function()
Definition: PAPI_get_opt.c:14
#define ERROR_RETURN(retval)
Definition: PAPI_get_opt.c:12
int main()
Definition: PAPI_get_opt.c:26
double tmp
int i
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Get PAPI library or event set options.
initialize the PAPI library.
Set PAPI library or event set options.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_DOMAIN
Definition: f90papi.h:159
#define PAPI_MAX_HWCTRS
Definition: f90papi.h:270
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_DOM_ALL
Definition: f90papi.h:261
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Return codes and api definitions.
static options_t options
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
int retval
Definition: zero_fork.c:53