PAPI 7.1.0.0
Loading...
Searching...
No Matches
PAPI_add_remove_event.c File Reference
Include dependency graph for PAPI_add_remove_event.c:

Go to the source code of this file.

Macros

#define NUM_EVENTS   2
 
#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
 

Functions

int main ()
 

Macro Definition Documentation

◆ ERROR_RETURN

#define ERROR_RETURN (   retval)    { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 11 of file PAPI_add_remove_event.c.

◆ NUM_EVENTS

#define NUM_EVENTS   2

Definition at line 10 of file PAPI_add_remove_event.c.

Function Documentation

◆ main()

int main ( )

Definition at line 13 of file PAPI_add_remove_event.c.

14{
15 int EventSet = PAPI_NULL;
16 int tmp, i;
17 /*must be initialized to PAPI_NULL before calling PAPI_create_event*/
18
19 long long values[NUM_EVENTS];
20 /*This is where we store the values we read from the eventset */
21
22 /* We use number to keep track of the number of events in the EventSet */
23 int retval, number;
24
25 char errstring[PAPI_MAX_STR_LEN];
26
27 /***************************************************************************
28 * This part initializes the library and compares the version number of the*
29 * header file, to the version of the library, if these don't match then it *
30 * is likely that PAPI won't work correctly.If there is an error, retval *
31 * keeps track of the version number. *
32 ***************************************************************************/
33
34
37
38
39 /* Creating the eventset */
42
43 /* Add Total Instructions Executed to the EventSet */
46
47 /* Add Total Cycles event to the EventSet */
50
51 /* get the number of events in the event set */
52 number = 0;
53 if ( (retval = PAPI_list_events(EventSet, NULL, &number)) != PAPI_OK)
55
56 printf("There are %d events in the event set\n", number);
57
58 /* Start counting */
59
60 if ( (retval = PAPI_start(EventSet)) != PAPI_OK)
62
63 /* you can replace your code here */
64 tmp=0;
65 for (i = 0; i < 2000000; i++)
66 {
67 tmp = i + tmp;
68 }
69
70
71 /* read the counter values and store them in the values array */
74
75 printf("The total instructions executed for the first loop are %lld \n", values[0] );
76 printf("The total cycles executed for the first loop are %lld \n",values[1]);
77
78 /* our slow code again */
79 tmp=0;
80 for (i = 0; i < 2000000; i++)
81 {
82 tmp = i + tmp;
83 }
84
85 /* Stop counting and store the values into the array */
88
89 printf("Total instructions executed are %lld \n", values[0] );
90 printf("Total cycles executed are %lld \n",values[1]);
91
92 /* Remove event: We are going to take the PAPI_TOT_INS from the eventset */
95 printf("Removing PAPI_TOT_INS from the eventset\n");
96
97 /* Now we list how many events are left on the event set */
98 number = 0;
99 if ((retval=PAPI_list_events(EventSet, NULL, &number))!= PAPI_OK)
101
102 printf("There is only %d event left in the eventset now\n", number);
103
104 /* free the resources used by PAPI */
106
107 exit(0);
108}
#define ERROR_RETURN(retval)
#define NUM_EVENTS
double tmp
int i
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
initialize the PAPI library.
list the events in an event set
Read hardware counters from an event set.
removes a hardware event 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
int retval
Definition: zero_fork.c:53