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

Go to the source code of this file.

Macros

#define INDEX1   100
 
#define INDEX5   500
 
#define MAX_WARN   10
 
#define MAX_ERROR   80
 
#define MAX_DIFF   14
 
#define FMA   0
 

Functions

static void resultline (int i, int j, int EventSet, int fail)
 
static void headerlines (char *title, int TESTS_QUIET)
 
static void print_help (char **argv)
 
static float inner_single (int n, float *x, float *y)
 
static double inner_double (int n, double *x, double *y)
 
static void vector_single (int n, float *a, float *x, float *y)
 
static void vector_double (int n, double *a, double *x, double *y)
 
static void matrix_single (int n, float *c, float *a, float *b)
 
static void matrix_double (int n, double *c, double *a, double *b)
 
static void reset_flops (char *title, int EventSet)
 
int main (int argc, char *argv[])
 

Variables

int TESTS_QUIET
 

Macro Definition Documentation

#define FMA   0

Definition at line 439 of file calibrate.c.

#define INDEX1   100

Definition at line 24 of file calibrate.c.

#define INDEX5   500

Definition at line 25 of file calibrate.c.

#define MAX_DIFF   14

Definition at line 29 of file calibrate.c.

#define MAX_ERROR   80

Definition at line 28 of file calibrate.c.

#define MAX_WARN   10

Definition at line 27 of file calibrate.c.

Function Documentation

static void headerlines ( char *  title,
int  TESTS_QUIET 
)
static

Definition at line 414 of file calibrate.c.

415 {
416  const PAPI_hw_info_t *hwinfo = NULL;
417 
418  if ( !TESTS_QUIET ) {
419  if ( papi_print_header( "", &hwinfo ) != PAPI_OK )
420  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
421 
422  printf( "\n%s:\n%8s %12s %12s %8s %8s\n", title, "i", "papi", "theory",
423  "diff", "%error" );
424  printf
425  ( "-------------------------------------------------------------------------\n" );
426  }
427 }
Hardware info structure.
Definition: papi.h:775
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: test_utils.c:21
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
int TESTS_QUIET
Definition: test_utils.c:11
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)

Here is the call graph for this function:

Here is the caller graph for this function:

static double inner_double ( int  n,
double x,
double y 
)
static

Definition at line 65 of file calibrate.c.

66 {
67  double aa = 0.0;
68  int i;
69 
70  for ( i = 0; i <= n; i++ )
71  aa = aa + x[i] * y[i];
72  return ( aa );
73 }
double aa[N]
Definition: byte_profile.c:30
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
int x
Definition: fileop.c:78
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

static float inner_single ( int  n,
float *  x,
float *  y 
)
static

Definition at line 54 of file calibrate.c.

55 {
56  float aa = 0.0;
57  int i;
58 
59  for ( i = 0; i <= n; i++ )
60  aa = aa + x[i] * y[i];
61  return ( aa );
62 }
double aa[N]
Definition: byte_profile.c:30
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
int x
Definition: fileop.c:78
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 131 of file calibrate.c.

132 {
133  extern void dummy( void * );
134 
135  float aa, *a, *b, *c, *x, *y;
136  double aad, *ad, *bd, *cd, *xd, *yd;
137  int i, j, n;
138  int inner = 0;
139  int vector = 0;
140  int matrix = 0;
141  int double_precision = 0;
142  int fail = 1;
143  int retval = PAPI_OK;
144  char papi_event_str[PAPI_MIN_STR_LEN] = "PAPI_FP_OPS";
145  int papi_event;
146  int EventSet = PAPI_NULL;
147 
148 /* Parse the input arguments */
149  for ( i = 0; i < argc; i++ ) {
150  if ( strstr( argv[i], "-i" ) )
151  inner = 1;
152  else if ( strstr( argv[i], "-f" ) )
153  fail = 0;
154  else if ( strstr( argv[i], "-v" ) )
155  vector = 1;
156  else if ( strstr( argv[i], "-m" ) )
157  matrix = 1;
158  else if ( strstr( argv[i], "-e" ) ) {
159  if ( ( argv[i + 1] == NULL ) || ( strlen( argv[i + 1] ) == 0 ) ) {
160  print_help( argv );
161  exit( 1 );
162  }
163  strncpy( papi_event_str, argv[i + 1], sizeof ( papi_event_str ) );
164  i++;
165  } else if ( strstr( argv[i], "-d" ) )
166  double_precision = 1;
167  else if ( strstr( argv[i], "-h" ) ) {
168  print_help( argv );
169  exit( 1 );
170  }
171  }
172 
173  /* if no options specified, set all tests to TRUE */
174  if ( inner + vector + matrix == 0 )
175  inner = vector = matrix = 1;
176 
177 
178  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
179 
180  if ( !TESTS_QUIET )
181  printf( "Initializing..." );
182 
183  /* Initialize PAPI */
185  if ( retval != PAPI_VER_CURRENT )
186  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
187 
188  /* Translate name */
189  retval = PAPI_event_name_to_code( papi_event_str, &papi_event );
190  if ( retval != PAPI_OK )
191  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
192 
193  if ( PAPI_query_event( papi_event ) != PAPI_OK )
194  test_skip( __FILE__, __LINE__, "PAPI_query_event", PAPI_ENOEVNT );
195 
196  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
197  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
198 
199  if ( ( retval = PAPI_add_event( EventSet, papi_event ) ) != PAPI_OK )
200  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
201 
202  printf( "\n" );
203 
204  retval = PAPI_OK;
205 
206  /* Inner Product test */
207  if ( inner ) {
208  /* Allocate the linear arrays */
209  if (double_precision) {
210  xd = malloc( INDEX5 * sizeof(double) );
211  yd = malloc( INDEX5 * sizeof(double) );
212  if ( !( xd && yd ) )
213  retval = PAPI_ENOMEM;
214  }
215  else {
216  x = malloc( INDEX5 * sizeof(float) );
217  y = malloc( INDEX5 * sizeof(float) );
218  if ( !( x && y ) )
219  retval = PAPI_ENOMEM;
220  }
221 
222  if ( retval == PAPI_OK ) {
223  headerlines( "Inner Product Test", TESTS_QUIET );
224 
225  /* step through the different array sizes */
226  for ( n = 0; n < INDEX5; n++ ) {
227  if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {
228 
229  /* Initialize the needed arrays at this size */
230  if ( double_precision ) {
231  for ( i = 0; i <= n; i++ ) {
232  xd[i] = ( double ) rand( ) * ( double ) 1.1;
233  yd[i] = ( double ) rand( ) * ( double ) 1.1;
234  }
235  } else {
236  for ( i = 0; i <= n; i++ ) {
237  x[i] = ( float ) rand( ) * ( float ) 1.1;
238  y[i] = ( float ) rand( ) * ( float ) 1.1;
239  }
240  }
241 
242  /* reset PAPI flops count */
243  reset_flops( "Inner Product Test", EventSet );
244 
245  /* do the multiplication */
246  if ( double_precision ) {
247  aad = inner_double( n, xd, yd );
248  dummy( ( void * ) &aad );
249  } else {
250  aa = inner_single( n, x, y );
251  dummy( ( void * ) &aa );
252  }
253  resultline( n, 1, EventSet, fail );
254  }
255  }
256  }
257  if (double_precision) {
258  free( xd );
259  free( yd );
260  } else {
261  free( x );
262  free( y );
263  }
264  }
265 
266  /* Matrix Vector test */
267  if ( vector && retval != PAPI_ENOMEM ) {
268  /* Allocate the needed arrays */
269  if (double_precision) {
270  ad = malloc( INDEX5 * INDEX5 * sizeof(double) );
271  xd = malloc( INDEX5 * sizeof(double) );
272  yd = malloc( INDEX5 * sizeof(double) );
273  if ( !( ad && xd && yd ) )
274  retval = PAPI_ENOMEM;
275  } else {
276  a = malloc( INDEX5 * INDEX5 * sizeof(float) );
277  x = malloc( INDEX5 * sizeof(float) );
278  y = malloc( INDEX5 * sizeof(float) );
279  if ( !( a && x && y ) )
280  retval = PAPI_ENOMEM;
281  }
282 
283  if ( retval == PAPI_OK ) {
284  headerlines( "Matrix Vector Test", TESTS_QUIET );
285 
286  /* step through the different array sizes */
287  for ( n = 0; n < INDEX5; n++ ) {
288  if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {
289 
290  /* Initialize the needed arrays at this size */
291  if ( double_precision ) {
292  for ( i = 0; i <= n; i++ ) {
293  yd[i] = 0.0;
294  xd[i] = ( double ) rand( ) * ( double ) 1.1;
295  for ( j = 0; j <= n; j++ )
296  ad[i * n + j] =
297  ( double ) rand( ) * ( double ) 1.1;
298  }
299  } else {
300  for ( i = 0; i <= n; i++ ) {
301  y[i] = 0.0;
302  x[i] = ( float ) rand( ) * ( float ) 1.1;
303  for ( j = 0; j <= n; j++ )
304  a[i * n + j] =
305  ( float ) rand( ) * ( float ) 1.1;
306  }
307  }
308 
309  /* reset PAPI flops count */
310  reset_flops( "Matrix Vector Test", EventSet );
311 
312  /* compute the resultant vector */
313  if ( double_precision ) {
314  vector_double( n, ad, xd, yd );
315  dummy( ( void * ) yd );
316  } else {
317  vector_single( n, a, x, y );
318  dummy( ( void * ) y );
319  }
320  resultline( n, 2, EventSet, fail );
321  }
322  }
323  }
324  if (double_precision) {
325  free( ad );
326  free( xd );
327  free( yd );
328  } else {
329  free( a );
330  free( x );
331  free( y );
332  }
333  }
334 
335  /* Matrix Multiply test */
336  if ( matrix && retval != PAPI_ENOMEM ) {
337  /* Allocate the needed arrays */
338  if (double_precision) {
339  ad = malloc( INDEX5 * INDEX5 * sizeof(double) );
340  bd = malloc( INDEX5 * INDEX5 * sizeof(double) );
341  cd = malloc( INDEX5 * INDEX5 * sizeof(double) );
342  if ( !( ad && bd && cd ) )
343  retval = PAPI_ENOMEM;
344  } else {
345  a = malloc( INDEX5 * INDEX5 * sizeof(float) );
346  b = malloc( INDEX5 * INDEX5 * sizeof(float) );
347  c = malloc( INDEX5 * INDEX5 * sizeof(float) );
348  if ( !( a && b && c ) )
349  retval = PAPI_ENOMEM;
350  }
351 
352 
353  if ( retval == PAPI_OK ) {
354  headerlines( "Matrix Multiply Test", TESTS_QUIET );
355 
356  /* step through the different array sizes */
357  for ( n = 0; n < INDEX5; n++ ) {
358  if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {
359 
360  /* Initialize the needed arrays at this size */
361  if ( double_precision ) {
362  for ( i = 0; i <= n * n + n; i++ ) {
363  cd[i] = 0.0;
364  ad[i] = ( double ) rand( ) * ( double ) 1.1;
365  bd[i] = ( double ) rand( ) * ( double ) 1.1;
366  }
367  } else {
368  for ( i = 0; i <= n * n + n; i++ ) {
369  c[i] = 0.0;
370  a[i] = ( float ) rand( ) * ( float ) 1.1;
371  b[i] = ( float ) rand( ) * ( float ) 1.1;
372  }
373  }
374 
375  /* reset PAPI flops count */
376  reset_flops( "Matrix Multiply Test", EventSet );
377 
378  /* compute the resultant matrix */
379  if ( double_precision ) {
380  matrix_double( n, cd, ad, bd );
381  dummy( ( void * ) c );
382  } else {
383  matrix_single( n, c, a, b );
384  dummy( ( void * ) c );
385  }
386  resultline( n, 3, EventSet, fail );
387  }
388  }
389  }
390  if (double_precision) {
391  free( ad );
392  free( bd );
393  free( cd );
394  } else {
395  free( a );
396  free( b );
397  free( c );
398  }
399  }
400 
401  /* exit with status code */
402  if ( retval == PAPI_ENOMEM )
403  test_fail( __FILE__, __LINE__, "malloc", retval );
404  else
405  test_pass( __FILE__, NULL, 0 );
406  exit( 1 );
407 }
#define PAPI_ENOMEM
Definition: fpapi.h:107
static void reset_flops(char *title, int EventSet)
Definition: calibrate.c:118
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
static void headerlines(char *title, int TESTS_QUIET)
Definition: calibrate.c:414
#define PAPI_NULL
Definition: fpapi.h:13
static void vector_double(int n, double *a, double *x, double *y)
Definition: calibrate.c:86
static void resultline(int i, int j, int EventSet, int fail)
Definition: calibrate.c:443
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_MIN_STR_LEN
Definition: fpapi.h:41
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static float inner_single(int n, float *x, float *y)
Definition: calibrate.c:54
static void vector_single(int n, float *a, float *x, float *y)
Definition: calibrate.c:76
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
double aa[N]
Definition: byte_profile.c:30
static void matrix_single(int n, float *c, float *a, float *b)
Definition: calibrate.c:96
#define printf
Definition: papi_test.h:125
double c
Definition: multiplex.c:22
static double
Definition: fileop.c:1281
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int dummy
Definition: iozone.c:19741
static void matrix_double(int n, double *c, double *a, double *b)
Definition: calibrate.c:107
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
#define INDEX5
Definition: calibrate.c:25
int PAPI_library_init(int version)
Definition: papi.c:495
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
free(dummyfile[xx])
static void print_help(char **argv)
Definition: calibrate.c:34
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define INDEX1
Definition: calibrate.c:24
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
int PAPI_query_event(int EventCode)
Definition: papi.c:696
int EventSet
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
int x
Definition: fileop.c:78
int rand()
static double inner_double(int n, double *x, double *y)
Definition: calibrate.c:65
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
void exit()
int n
Definition: mendes-alt.c:164

Here is the call graph for this function:

static void matrix_double ( int  n,
double c,
double a,
double b 
)
static

Definition at line 107 of file calibrate.c.

108 {
109  int i, j, k;
110 
111  for ( i = 0; i <= n; i++ )
112  for ( j = 0; j <= n; j++ )
113  for ( k = 0; k <= n; k++ )
114  c[i * n + j] = c[i * n + j] + a[i * n + k] * b[k * n + j];
115 }
double c
Definition: multiplex.c:22
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int i
Definition: fileop.c:140
int k
Definition: iozone.c:19136
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
long j
Definition: iozone.c:19135
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

static void matrix_single ( int  n,
float *  c,
float *  a,
float *  b 
)
static

Definition at line 96 of file calibrate.c.

97 {
98  int i, j, k;
99 
100  for ( i = 0; i <= n; i++ )
101  for ( j = 0; j <= n; j++ )
102  for ( k = 0; k <= n; k++ )
103  c[i * n + j] = c[i * n + j] + a[i * n + k] * b[k * n + j];
104 }
double c
Definition: multiplex.c:22
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int i
Definition: fileop.c:140
int k
Definition: iozone.c:19136
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
long j
Definition: iozone.c:19135
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

static void print_help ( char **  argv)
static

Definition at line 34 of file calibrate.c.

35 {
36  printf( "Usage: %s [-ivmdh] [-e event]\n", argv[0] );
37  printf( "Options:\n\n" );
38  printf( "\t-i Inner Product test.\n" );
39  printf( "\t-v Matrix-Vector multiply test.\n" );
40  printf( "\t-m Matrix-Matrix multiply test.\n" );
41  printf( "\t-d Double precision data. Default is float.\n" );
42  printf
43  ( "\t-e event Use <event> as PAPI event instead of PAPI_FP_OPS\n" );
44  printf( "\t-f Suppress failures\n" );
45  printf( "\t-h Print this help message\n" );
46  printf( "\n" );
47  printf
48  ( "This test measures floating point operations for the specified test.\n" );
49  printf( "Operations can be performed in single or double precision.\n" );
50  printf( "Default operation is all three tests in single precision.\n" );
51 }
#define printf
Definition: papi_test.h:125
char ** argv
Definition: iozone.c:1610

Here is the caller graph for this function:

static void reset_flops ( char *  title,
int  EventSet 
)
static

Definition at line 118 of file calibrate.c.

119 {
120  int retval;
121  char err_str[PAPI_MAX_STR_LEN];
122 
123  retval = PAPI_start( EventSet );
124  if ( retval != PAPI_OK ) {
125  sprintf( err_str, "%s: PAPI_start", title );
126  test_fail( __FILE__, __LINE__, err_str, retval );
127  }
128 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
return PAPI_OK
Definition: linux-nvml.c:458
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int EventSet
int PAPI_start(int EventSet)
Definition: papi.c:2026
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function:

static void resultline ( int  i,
int  j,
int  EventSet,
int  fail 
)
static

Definition at line 443 of file calibrate.c.

444 {
445  float ferror = 0;
446  long long flpins = 0;
447  long long papi, theory;
448  int diff, retval;
449  char err_str[PAPI_MAX_STR_LEN];
450 
451  retval = PAPI_stop( EventSet, &flpins );
452  if ( retval != PAPI_OK )
453  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
454 
455  i++; /* convert to 1s base */
456  theory = 2;
457  while ( j-- )
458  theory *= i; /* theoretical ops */
459  papi = flpins << FMA;
460 
461  diff = ( int ) ( papi - theory );
462 
463  ferror = ( ( float ) abs( diff ) ) / ( ( float ) theory ) * 100;
464 
465  printf( "%8d %12lld %12lld %8d %10.4f\n", i, papi, theory, diff, ferror );
466 
467  if ( ferror > MAX_WARN && abs( diff ) > MAX_DIFF && i > 20 ) {
468  sprintf( err_str, "Calibrate: difference exceeds %d percent", MAX_WARN );
469  test_warn( __FILE__, __LINE__, err_str, 0 );
470  }
471  if (fail) {
472  if ( ferror > MAX_ERROR && abs( diff ) > MAX_DIFF && i > 20 ) {
473  sprintf( err_str, "Calibrate: error exceeds %d percent", MAX_ERROR );
474  test_fail( __FILE__, __LINE__, err_str, PAPI_EMISC );
475  }
476  }
477 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_EMISC
Definition: fpapi.h:119
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define MAX_ERROR
Definition: calibrate.c:28
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
#define FMA
Definition: calibrate.c:439
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int i
Definition: fileop.c:140
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
#define MAX_WARN
Definition: calibrate.c:27
int EventSet
int
Definition: iozone.c:18528
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
#define MAX_DIFF
Definition: calibrate.c:29

Here is the call graph for this function:

Here is the caller graph for this function:

static void vector_double ( int  n,
double a,
double x,
double y 
)
static

Definition at line 86 of file calibrate.c.

87 {
88  int i, j;
89 
90  for ( i = 0; i <= n; i++ )
91  for ( j = 0; j <= n; j++ )
92  y[i] = y[i] + a[i * n + j] * x[i];
93 }
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
int x
Definition: fileop.c:78
long j
Definition: iozone.c:19135
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

static void vector_single ( int  n,
float *  a,
float *  x,
float *  y 
)
static

Definition at line 76 of file calibrate.c.

77 {
78  int i, j;
79 
80  for ( i = 0; i <= n; i++ )
81  for ( j = 0; j <= n; j++ )
82  y[i] = y[i] + a[i * n + j] * x[i];
83 }
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
int x
Definition: fileop.c:78
long j
Definition: iozone.c:19135
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

Variable Documentation

int TESTS_QUIET

Definition at line 11 of file test_utils.c.