PAPI  5.7.0.0
benchPCP.c File Reference
Include dependency graph for benchPCP.c:

Go to the source code of this file.

Data Structures

union  convert_64_t
 

Macros

#define mConvertUsec(timeval_)   ((double) (timeval_.tv_sec*1000000+timeval_.tv_usec)) /* avoid typos, make it a double. */
 

Functions

int main (int argc, char **argv)
 

Variables

static struct timeval t1 t2
 
int EVENTREADS =0
 

Macro Definition Documentation

◆ mConvertUsec

#define mConvertUsec (   timeval_)    ((double) (timeval_.tv_sec*1000000+timeval_.tv_usec)) /* avoid typos, make it a double. */

Definition at line 30 of file benchPCP.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file benchPCP.c.

47  { // args to set two events.
48  int i,ret;
49  int EventSet = PAPI_NULL;
50  char errMsg[1024]; // space for an error message with more info.
51  char *pcpName; // The pcp name.
52  if (argc == 1) { // If no arguments given,
53  printf("Initialize, Event Read Avg uS\n"); // OUTPUT Header for CSV.
54  return 0; // done.
55  }
56 
57  if (argc != 3) {
58  fprintf(stderr, "%s:%i ERROR Invalid number of arguments; must be 0 or 2.\n", __FILE__, __LINE__); // report.
59  fprintf(stderr, "%s readsToAvg Event-Name\n", argv[0]);
60  exit(-1);
61  }
62 
63  // Get args.
64  EVENTREADS = atoi(argv[1]); // get event reads.
65  if (EVENTREADS < 1) {
66  fprintf(stderr, "%s:%i ERROR readsToAvg must be > 0.\n", __FILE__, __LINE__); // report.
67  fprintf(stderr, "%s readsToAvg Event-Name\n", argv[0]);
68  exit(-1);
69  }
70 
71  pcpName = argv[2]; // collect the pcp event name.
72 
73  gettimeofday(&t1, NULL);
75  gettimeofday(&t2, NULL);
76 
77  if (ret != PAPI_VER_CURRENT) { // if we failed,
78  printf("ERROR PAPI library init failed.\n"); // Show abort in file.
79  test_fail(__FILE__, __LINE__, "PAPI_library_init failed\n", ret); // report.
80  }
81 
82  printf("%9.1f,", (mConvertUsec(t2)-mConvertUsec(t1))); // OUTPUT PAPI library init time.
83 
84 // fprintf(stderr, "Benching Event Read with PAPI %d.%d.%d\n",
85 // PAPI_VERSION_MAJOR( PAPI_VERSION ),
86 // PAPI_VERSION_MINOR( PAPI_VERSION ),
87 // PAPI_VERSION_REVISION( PAPI_VERSION ) );
88 
89  // Library is initialized.
90  ret = PAPI_create_eventset(&EventSet); // Create an event.
91  if (ret != PAPI_OK) { // If that failed, report and exit.
92  fprintf(stderr, "ERROR PAPI_create_eventset failed.\n");
93  test_fail(__FILE__, __LINE__, "PAPI_create_eventset failed.\n", ret);
94  }
95 
96  ret=PAPI_add_named_event(EventSet,pcpName); // Try to add it for counting.
97  if (ret != PAPI_OK) { // If that failed, report it.
98  sprintf(errMsg, "PAPI_add_named_event('%s') failed.\n", pcpName);
99  printf("ERROR %s\n", errMsg);
100  test_fail( __FILE__, __LINE__, errMsg, ret);
101  }
102 
103  //----------------------------------------------------------------------------------------------
104  // Testing, we just read each event EVENTREADS times, and record the times read.
105  // We overwrite the previous result every time, we aren't interested in the values.
106  // 'volatile' to avoid compiler optimizing out the loop.
107  //----------------------------------------------------------------------------------------------
108  long long pcpValue;
109 
110  // Begin event timing.
111  ret = PAPI_start(EventSet); // start counting.
112  if (ret != PAPI_OK) { // If that failed, report it.
113  printf("ERROR PAPI_start EventSet failed.\n"); // Show abort in file.
114  test_fail( __FILE__, __LINE__, "PAPI_start_event(EventSet) failed.\n", ret); // report and exit.
115  }
116 
117  gettimeofday(&t1, NULL);
118  for (i=0; i<EVENTREADS; i++) { // For all the PCP iterations,
119  ret = PAPI_read(EventSet, &pcpValue); // .. read without a stop.
120  if (ret != PAPI_OK) { // .. If that failed, report it.
121  printf("ERROR PAPI_read EventSet failed.\n"); // Show abort in file.
122  test_fail( __FILE__, __LINE__, "PAPI_read(EventSet) failed.\n", ret);
123  }
124  }
125  gettimeofday(&t2, NULL);
126 
127  ret = PAPI_stop(EventSet, &pcpValue); // stop counting, get final value.
128  if (ret != PAPI_OK) { // If that failed, report it.
129  printf("ERROR PAPI_stop EventSet failed.\n"); // Show abort in file.
130  test_fail( __FILE__, __LINE__, "PAPI_stop_event(PAPIEventSet, &papiValues[FINAL]) failed.\n", ret);
131  }
132 
133  printf("%9.1f\n", (mConvertUsec(t2)-mConvertUsec(t1))/((double) EVENTREADS)); // compute average, finish line.
134 
135  ret = PAPI_cleanup_eventset(EventSet); // Try a cleanup.
136  if (ret != PAPI_OK) { // If that failed, report it.
137  printf("ERROR PAPI_cleanup_eventset failed.\n"); // Show abort in file.
138  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset(EventSet) failed.\n", ret);
139  }
140 
141  ret = PAPI_destroy_eventset(&EventSet); // Deallocate. No memory leaks!
142  if (ret != PAPI_OK) { // If that failed, report it.
143  printf("ERROR PAPI_destroy_eventset failed.\n"); // Show abort in file.
144  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset(EventSet) failed.\n", ret);
145  }
146 
147  //----------------------------------------------------------------------------------------------
148  // Done. cleanup.
149  //----------------------------------------------------------------------------------------------
150  PAPI_shutdown(); // get out of papi.
151 // fprintf(stderr, "PAPI Shutdown completed.\n"); // If we are verbose,
152 // test_pass( __FILE__ ); // Note the test passed.
153  return 0; // Exit with all okay.
154 } // END main.
#define PAPI_OK
Definition: fpapi.h:105
static struct timeval t1 t2
Definition: benchPCP.c:31
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int EVENTREADS
Definition: benchPCP.c:32
#define mConvertUsec(timeval_)
Definition: benchPCP.c:30
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
volatile double t1
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int PAPI_library_init(int version)
Definition: papi.c:500
void PAPI_shutdown(void)
Definition: papi.c:4461
#define PAPI_NULL
Definition: fpapi.h:13
long long ret
Definition: iozone.c:1346
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int gettimeofday(void *ptr1, void *ptr2)
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
void exit()
int i
Definition: fileop.c:140
Here is the call graph for this function:

Variable Documentation

◆ EVENTREADS

int EVENTREADS =0

Definition at line 32 of file benchPCP.c.

◆ t2

struct timeval t1 t2
static

Definition at line 31 of file benchPCP.c.