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

Go to the source code of this file.

Macros

#define NUM_EVENT   2
 
#define THRESHOLD   100000
 
#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 17 of file PAPI_add_remove_events.c.

◆ NUM_EVENT

#define NUM_EVENT   2

Definition at line 15 of file PAPI_add_remove_events.c.

◆ THRESHOLD

#define THRESHOLD   100000

Definition at line 16 of file PAPI_add_remove_events.c.

Function Documentation

◆ main()

int main ( )

Definition at line 20 of file PAPI_add_remove_events.c.

20 {
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
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
FILE * stderr
int retval
Definition: zero_fork.c:53