PAPI 7.1.0.0
Loading...
Searching...
No Matches
PAPI_add_remove_events.c
Go to the documentation of this file.
1/******************************************************************************
2 * This is a simple low level function demonstration on using PAPI_add_events *
3 * to add an array of events to a created eventset, we are going to use these *
4 * events to monitor a set of instructions, start the counters, read the *
5 * counters and then cleanup the eventset when done. In this example we use *
6 * the presets PAPI_TOT_INS and PAPI_TOT_CYC. PAPI_add_events,PAPI_start, *
7 * PAPI_stop, PAPI_clean_eventset, PAPI_destroy_eventset and *
8 * PAPI_create_eventset all return PAPI_OK(which is 0) when succesful. *
9 ******************************************************************************/
10
11#include <stdio.h>
12#include <stdlib.h>
13#include "papi.h" /* This needs to be included every time you use PAPI */
14
15#define NUM_EVENT 2
16#define THRESHOLD 100000
17#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
18
19
20int main(){
21
22 int i,retval,tmp;
23 int EventSet = PAPI_NULL;
24 /*must be initialized to PAPI_NULL before calling PAPI_create_event*/
25
26 int event_codes[NUM_EVENT]={PAPI_TOT_INS,PAPI_TOT_CYC};
27 char errstring[PAPI_MAX_STR_LEN];
28 long long values[NUM_EVENT];
29
30 /***************************************************************************
31 * This part initializes the library and compares the version number of the *
32 * header file, to the version of the library, if these don't match then it *
33 * is likely that PAPI won't work correctly.If there is an error, retval *
34 * keeps track of the version number. *
35 ****************************************************************************/
36
38 {
39 fprintf(stderr, "Error: %s\n", errstring);
40 exit(1);
41 }
42
43
44 /* Creating event set */
47
48
49 /* Add the array of events PAPI_TOT_INS and PAPI_TOT_CYC to the eventset*/
50 if ((retval=PAPI_add_events(EventSet, event_codes, NUM_EVENT)) != PAPI_OK)
52
53
54 /* Start counting */
57
58 /*** this is where your computation goes *********/
59 for(i=0;i<1000;i++)
60 {
61 tmp = tmp+i;
62 }
63
64 /* Stop counting, this reads from the counter as well as stop it. */
67
68 printf("\nThe total instructions executed are %lld, total cycles %lld\n",
69 values[0],values[1]);
70
71
74
75 /* Free all memory and data structures, EventSet must be empty. */
78
79 /* free the resources used by PAPI */
81
82 exit(0);
83}
#define ERROR_RETURN(retval)
#define NUM_EVENT
int main()
double tmp
int i
add multiple PAPI presets or native hardware events to an event set
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
initialize the PAPI library.
Remove an array of hardware event codes from a PAPI event set.
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_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
int retval
Definition: zero_fork.c:53