PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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

#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.

#define NUM_EVENT   2

Definition at line 15 of file PAPI_add_remove_events.c.

#define THRESHOLD   100000

Definition at line 16 of file PAPI_add_remove_events.c.

Function Documentation

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 */
45  if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
46  ERROR_RETURN(retval);
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)
51  ERROR_RETURN(retval);
52 
53 
54  /* Start counting */
55  if ( (retval=PAPI_start(EventSet)) != PAPI_OK)
56  ERROR_RETURN(retval);
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. */
65  if ( (retval=PAPI_stop(EventSet,values)) != PAPI_OK)
66  ERROR_RETURN(retval);
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)
73  ERROR_RETURN(retval);
74 
75  /* Free all memory and data structures, EventSet must be empty. */
76  if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
77  ERROR_RETURN(retval);
78 
79  /* free the resources used by PAPI */
80  PAPI_shutdown();
81 
82  exit(0);
83 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define NUM_EVENT
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
int PAPI_remove_events(int EventSet, int *Events, int number)
Definition: papi.c:5857
#define printf
Definition: papi_test.h:125
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5769
#define ERROR_RETURN(retval)
int PAPI_library_init(int version)
Definition: papi.c:497
int i
Definition: fileop.c:140
void PAPI_shutdown(void)
Definition: papi.c:4400
#define PAPI_TOT_CYC
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
#define PAPI_VER_CURRENT
Definition: papi.h:223
void exit()

Here is the call graph for this function: