PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PAPI_get_opt.c File Reference
Include dependency graph for PAPI_get_opt.c:

Go to the source code of this file.

Macros

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

Functions

int poorly_tuned_function ()
 
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 12 of file PAPI_get_opt.c.

Function Documentation

int main ( )

Definition at line 26 of file PAPI_get_opt.c.

27 {
28 
29  int num, retval, EventSet = PAPI_NULL;
31  long long values[2];
32 
33  /****************************************************************************
34  * This part initializes the library and compares the version number of the *
35  * header file, to the version of the library, if these don't match then it *
36  * is likely that PAPI won't work correctly.If there is an error, retval *
37  * keeps track of the version number. *
38  ****************************************************************************/
39 
41  {
42  printf("Library initialization error! \n");
43  exit(1);
44  }
45 
46  /*PAPI_get_opt returns a negative number if there is an error */
47 
48  /* This call returns the maximum available hardware counters */
49  if((num = PAPI_get_opt(PAPI_MAX_HWCTRS,NULL)) <= 0)
50  ERROR_RETURN(num);
51 
52 
53  printf("This machine has %d counters.\n",num);
54 
55  if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
56  ERROR_RETURN(retval);
57 
58  /* Set the domain of this EventSet to counter user and
59  kernel modes for this process. */
60 
61  memset(&options,0x0,sizeof(options));
62 
63  options.domain.eventset = EventSet;
64  /* Default domain is PAPI_DOM_USER */
65  options.domain.domain = PAPI_DOM_ALL;
66  /* this sets the options for the domain */
67  if ((retval=PAPI_set_opt(PAPI_DOMAIN, &options)) != PAPI_OK)
68  ERROR_RETURN(retval);
69  /* Add Total Instructions Executed event to the EventSet */
70  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
71  ERROR_RETURN(retval);
72 
73  /* Add Total Cycles Executed event to the EventSet */
74  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK)
75  ERROR_RETURN(retval);
76 
77  /* Start counting */
78  if((retval=PAPI_start(EventSet)) != PAPI_OK)
79  ERROR_RETURN(retval);
80 
82 
83  /* Stop counting */
84  if((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
85  ERROR_RETURN(retval);
86 
87  printf(" Total instructions: %lld Total Cycles: %lld \n", values[0],
88  values[1]);
89 
90  /* clean up */
91  PAPI_shutdown();
92 
93  exit(0);
94 }
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define PAPI_TOT_INS
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:845
#define printf
Definition: papi_test.h:125
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3409
int poorly_tuned_function()
Definition: PAPI_get_opt.c:14
int PAPI_library_init(int version)
Definition: papi.c:497
void PAPI_shutdown(void)
Definition: papi.c:4400
#define PAPI_TOT_CYC
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
void int num
Definition: iozone.c:22151
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define PAPI_DOMAIN
Definition: papi.h:431
#define PAPI_MAX_HWCTRS
Definition: papi.h:441
PAPI_domain_option_t domain
Definition: papi.h:852
#define ERROR_RETURN(retval)
Definition: PAPI_get_opt.c:12
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
#define PAPI_VER_CURRENT
Definition: papi.h:223
static options_t options
void exit()

Here is the call graph for this function:

int poorly_tuned_function ( )

Definition at line 14 of file PAPI_get_opt.c.

15 {
16  float tmp;
17  int i;
18 
19  for(i=1; i<2000; i++)
20  {
21  tmp=(tmp+100)/i;
22  }
23  return 0;
24 }
int i
Definition: fileop.c:140
long long tmp
Definition: iozone.c:12031

Here is the caller graph for this function: