PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PAPI_reset.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * PAPI_reset - resets the hardware event counters used by an EventSet. *
3  *****************************************************************************/
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "papi.h" /* This needs to be included every time you use PAPI */
8 
9 #define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
10 
12 {
13  float tmp;
14  int i;
15 
16  for(i=1; i<2000; i++)
17  {
18  tmp=(tmp+100)/i;
19  }
20  return 0;
21 }
22 
23 int main()
24 {
25  int EventSet = PAPI_NULL;
26  /*must be initialized to PAPI_NULL before calling PAPI_create_event*/
27 
28  int retval;
29  unsigned int event_code=PAPI_TOT_INS;
30  /* By default monitor total instructions */
31 
32  char errstring[PAPI_MAX_STR_LEN];
33  long long values[1];
34 
35  /****************************************************************************
36  * This part initializes the library and compares the version number of the *
37  * header file, to the version of the library, if these don't match then it *
38  * is likely that PAPI won't work correctly.If there is an error, retval *
39  * keeps track of the version number. *
40  ****************************************************************************/
41 
43  {
44  printf("Library initialization error! \n");
45  exit(1);
46  }
47 
48  /* Creating the eventset */
49  if ( (retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
50  ERROR_RETURN(retval);
51 
52  /* Add Total Instructions Executed to our EventSet */
53  if ((retval=PAPI_add_event(EventSet, event_code)) != PAPI_OK)
54  ERROR_RETURN(retval);
55 
56  /* Start counting */
57  if((retval=PAPI_start(EventSet)) != PAPI_OK)
58  ERROR_RETURN(retval);
59 
61 
62  /* Stop counting */
63  if((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
64  ERROR_RETURN(retval);
65 
66 
67  printf("The first time read value is %lld\n",values[0]);
68 
69  /* This zeroes out the counters on the eventset that was created */
70  if((retval=PAPI_reset(EventSet)) != PAPI_OK)
71  ERROR_RETURN(retval);
72 
73  /* Start counting */
74  if((retval=PAPI_start(EventSet)) != PAPI_OK)
75  ERROR_RETURN(retval);
76 
78 
79  /* Stop counting */
80  if((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
81  ERROR_RETURN(retval);
82 
83  printf("The second time read value is %lld\n",values[0]);
84 
85  /* free the resources used by PAPI */
86  PAPI_shutdown();
87 
88  exit(0);
89 }
90 
91 
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
int PAPI_reset(int EventSet)
Definition: papi.c:2403
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
Return codes and api definitions.
int poorly_tuned_function()
Definition: PAPI_get_opt.c:14
int PAPI_library_init(int version)
Definition: papi.c:497
int i
Definition: fileop.c:140
void PAPI_shutdown(void)
Definition: papi.c:4400
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define ERROR_RETURN(retval)
Definition: PAPI_reset.c:9
#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
int main(int argc, char **argv)
List all appio events codes and names.
void exit()