PAPI  5.7.0.0
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 */
55  if ( (retval=PAPI_start(EventSet)) != PAPI_OK)
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 
72  if ( (retval=PAPI_remove_events(EventSet,event_codes, NUM_EVENT))!=PAPI_OK)
74 
75  /* Free all memory and data structures, EventSet must be empty. */
78 
79  /* free the resources used by PAPI */
80  PAPI_shutdown();
81 
82  exit(0);
83 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define NUM_EVENT
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
int retval
Definition: zero_fork.c:53
int PAPI_remove_events(int EventSet, int *Events, int number)
Definition: papi.c:5931
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5843
double tmp
#define ERROR_RETURN(retval)
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_TOT_INS
Definition: fpapi.h:186
void PAPI_shutdown(void)
Definition: papi.c:4461
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_TOT_CYC
Definition: fpapi.h:195
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void exit()
int i
Definition: fileop.c:140
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the call graph for this function: