PAPI 7.1.0.0
Loading...
Searching...
No Matches
PAPI_overflow.c
Go to the documentation of this file.
1/*****************************************************************************
2* This example shows how to use PAPI_overflow to set up an event set to *
3* begin registering overflows.
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#include <pthread.h>
10
11#define OVER_FMT "handler(%d ) Overflow at %p! bit=%#llx \n"
12#define THRESHOLD 100000
13#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
14
15int total = 0; /* we use total to track the amount of overflows that occurred */
16
17/* THis is the handler called by PAPI_overflow*/
18void
19handler(int EventSet, void *address, long long overflow_vector, void *context)
20{
21 fprintf(stderr, OVER_FMT, EventSet, address, overflow_vector);
22 total++;
23}
24
25
26int main ()
27{
28 int EventSet = PAPI_NULL;
29 /* must be set to null before calling PAPI_create_eventset */
30
31 char errstring[PAPI_MAX_STR_LEN];
32 long long (values[2])[2];
33 int retval, i;
34 double tmp = 0;
35 int PAPI_event; /* a place holder for an event preset */
37
38
39 /****************************************************************************
40 * This part initializes the library and compares the version number of the *
41 * header file, to the version of the library, if these don't match then it *
42 * is likely that PAPI won't work correctly.If there is an error, retval *
43 * keeps track of the version number. *
44 ****************************************************************************/
45
47 {
48 printf("Library initialization error! \n");
49 exit(1);
50 }
51
52 /* Here we create the eventset */
55
57
58 /* Here we are querying for the existence of the PAPI presets */
60 {
62
65
66 printf ("PAPI_TOT_INS not available on this platform.");
67 printf (" so subst PAPI_event with PAPI_TOT_CYC !\n\n");
68
69 }
70
71
72 /* PAPI_event_code_to_name is used to convert a PAPI preset from
73 its integer value to its string name. */
76
77 /* add event to the event set */
80
81 /* register overflow and set up threshold */
82 /* The threshold "THRESHOLD" was set to 100000 */
84 handler)) != PAPI_OK)
86
87 printf ("Here are the addresses at which overflows occurred and overflow vectors \n");
88 printf ("--------------------------------------------------------------\n");
89
90
91 /* Start counting */
92
95
96 for (i = 0; i < 2000000; i++)
97 {
98 tmp = 1.01 + tmp;
99 tmp++;
100 }
101
102 /* Stops the counters and reads the counter values into the values array */
103 if ( (retval=PAPI_stop (EventSet, values[0])) != PAPI_OK)
105
106
107 printf ("The total no of overflows was %d\n", total);
108
109 /* clear the overflow status */
111 handler)) != PAPI_OK)
113
114 /************************************************************************
115 * PAPI_cleanup_eventset can only be used after the counter has been *
116 * stopped then it remove all events in the eventset *
117 ************************************************************************/
120
121 /* Free all memory and data structures, EventSet must be empty. */
124
125 /* free the resources used by PAPI */
127
128 exit(0);
129}
double tmp
int i
#define OVER_FMT
Definition: PAPI_overflow.c:11
#define THRESHOLD
Definition: PAPI_overflow.c:12
#define ERROR_RETURN(retval)
Definition: PAPI_overflow.c:13
int total
Definition: PAPI_overflow.c:15
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: PAPI_overflow.c:19
int main()
Definition: PAPI_overflow.c:26
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a numeric hardware event code to a name.
initialize the PAPI library.
Set up an event set to begin registering overflows.
Query if PAPI event exists.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#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_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_TOT_INS
Definition: f90papi.h:317
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Return codes and api definitions.
FILE * stderr
long long int long long
Definition: sde_internal.h:85
int retval
Definition: zero_fork.c:53