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

Go to the source code of this file.

Macros

#define MAXEVENTS   4
 
#define SLEEPTIME   100
 
#define MINCOUNTS   100000
 

Functions

static double dummy3 (double x, int iters)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define MAXEVENTS   4

Definition at line 15 of file branches.c.

#define MINCOUNTS   100000

Definition at line 17 of file branches.c.

#define SLEEPTIME   100

Definition at line 16 of file branches.c.

Function Documentation

static double dummy3 ( double  x,
int  iters 
)
static

Definition at line 217 of file branches.c.

218 {
219  int i;
220  double w, y, z, a, b, c, d, e, f, g, h;
221  double one;
222  one = 1.0;
223  w = x;
224  y = x;
225  z = x;
226  a = x;
227  b = x;
228  c = x;
229  d = x;
230  e = x;
231  f = x;
232  g = x;
233  h = x;
234  for ( i = 1; i <= iters; i++ ) {
235  w = w * 1.000000000001 + one;
236  y = y * 1.000000000002 + one;
237  z = z * 1.000000000003 + one;
238  a = a * 1.000000000004 + one;
239  b = b * 1.000000000005 + one;
240  c = c * 0.999999999999 + one;
241  d = d * 0.999999999998 + one;
242  e = e * 0.999999999997 + one;
243  f = f * 0.999999999996 + one;
244  g = h * 0.999999999995 + one;
245  h = h * 1.000000000006 + one;
246  }
247  return 2.0 * ( a + b + c + d + e + f + w + x + y + z + g + h );
248 }
double f(double a)
Definition: cpi.c:23
double c
Definition: multiplex.c:22
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 one
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
int x
Definition: fileop.c:78

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file branches.c.

23 {
24  PAPI_event_info_t info;
25  int i, j, retval;
26  int iters = 10000000;
27  double x = 1.1, y;
28  long long t1, t2;
29  long long values[MAXEVENTS], refvalues[MAXEVENTS];
30  int sleep_time = SLEEPTIME;
31  double spread[MAXEVENTS];
32  int nevents = MAXEVENTS;
33  int eventset = PAPI_NULL;
34  int events[MAXEVENTS];
35 
36  events[0] = PAPI_BR_NTK;
37  events[1] = PAPI_BR_PRC;
38  events[2] = PAPI_BR_INS;
39  events[3] = PAPI_BR_MSP;
40 /*
41  events[3]=PAPI_BR_CN;
42  events[4]=PAPI_BR_UCN;*/
43  /*events[5]=PAPI_BR_TKN; */
44 
45 
46  for ( i = 0; i < MAXEVENTS; i++ ) {
47  values[i] = 0;
48  }
49 
50  if ( argc > 1 ) {
51  if ( !strcmp( argv[1], "TESTS_QUIET" ) )
52  tests_quiet( argc, argv );
53  else {
54  sleep_time = atoi( argv[1] );
55  if ( sleep_time <= 0 )
56  sleep_time = SLEEPTIME;
57  }
58  }
59 
60  if ( !TESTS_QUIET ) {
61  printf( "\nAccuracy check of branch presets.\n" );
62  printf( "Comparing a measurement with separate measurements.\n\n" );
63  }
64 
65  if ( ( retval =
67  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
68 
69  if ( ( retval = PAPI_create_eventset( &eventset ) ) )
70  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
71 
72 #ifdef MPX
73  if ( ( retval = PAPI_multiplex_init( ) ) )
74  test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
75 
76  if ( ( retval = PAPI_set_multiplex( eventset ) ) )
77  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
78 #endif
79 
80  nevents = 0;
81 
82  for ( i = 0; i < MAXEVENTS; i++ ) {
83  if ( PAPI_query_event( events[i] ) != PAPI_OK )
84  continue;
85  if ( PAPI_add_event( eventset, events[i] ) == PAPI_OK ) {
86  events[nevents] = events[i];
87  nevents++;
88  }
89  }
90 
91  if ( nevents < 1 )
92  test_skip( __FILE__, __LINE__, "Not enough events left...", 0 );
93 
94  /* Find a reasonable number of iterations (each
95  * event active 20 times) during the measurement
96  */
97  t2 = (long long)(10000 * 20) * nevents; /* Target: 10000 usec/multiplex, 20 repeats */
98  if ( t2 > 30e6 )
99  test_skip( __FILE__, __LINE__, "This test takes too much time",
100  retval );
101 
102  /* Measure one run */
103  t1 = PAPI_get_real_usec( );
104  y = dummy3( x, iters );
105  t1 = PAPI_get_real_usec( ) - t1;
106 
107  if ( t2 > t1 ) /* Scale up execution time to match t2 */
108  iters = iters * ( int ) ( t2 / t1 );
109  else if ( t1 > 30e6 ) /* Make sure execution time is < 30s per repeated test */
110  test_skip( __FILE__, __LINE__, "This test takes too much time",
111  retval );
112 
113  x = 1.0;
114 
115  if ( !TESTS_QUIET )
116  printf( "\nFirst run: Together.\n" );
117 
118  t1 = PAPI_get_real_usec( );
119  if ( ( retval = PAPI_start( eventset ) ) )
120  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
121  y = dummy3( x, iters );
122  if ( ( retval = PAPI_stop( eventset, values ) ) )
123  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
124  t2 = PAPI_get_real_usec( );
125 
126  if ( !TESTS_QUIET ) {
127  printf( "\tOperations= %.1f Mflop", y * 1e-6 );
128  printf( "\t(%g Mflop/s)\n\n", ( y / ( double ) ( t2 - t1 ) ) );
129  printf( "PAPI grouped measurement:\n" );
130  }
131  for ( j = 0; j < nevents; j++ ) {
132  PAPI_get_event_info( events[j], &info );
133  if ( !TESTS_QUIET ) {
134  printf( "%20s = ", info.short_descr );
135  printf( LLDFMT, values[j] );
136  printf( "\n" );
137  }
138  }
139  if ( !TESTS_QUIET )
140  printf( "\n" );
141 
142 
143  if ( ( retval = PAPI_remove_events( eventset, events, nevents ) ) )
144  test_fail( __FILE__, __LINE__, "PAPI_remove_events", retval );
145  if ( ( retval = PAPI_destroy_eventset( &eventset ) ) )
146  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
147  eventset = PAPI_NULL;
148  if ( ( retval = PAPI_create_eventset( &eventset ) ) )
149  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
150 
151  for ( i = 0; i < nevents; i++ ) {
152 
153  if ( ( retval = PAPI_cleanup_eventset( eventset ) ) )
154  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
155  if ( ( retval = PAPI_add_event( eventset, events[i] ) ) )
156  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
157 
158  x = 1.0;
159 
160  if ( !TESTS_QUIET )
161  printf( "\nReference measurement %d (of %d):\n", i + 1, nevents );
162 
163  t1 = PAPI_get_real_usec( );
164  if ( ( retval = PAPI_start( eventset ) ) )
165  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
166  y = dummy3( x, iters );
167  if ( ( retval = PAPI_stop( eventset, &refvalues[i] ) ) )
168  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
169  t2 = PAPI_get_real_usec( );
170 
171  if ( !TESTS_QUIET ) {
172  printf( "\tOperations= %.1f Mflop", y * 1e-6 );
173  printf( "\t(%g Mflop/s)\n\n", ( y / ( double ) ( t2 - t1 ) ) );
174  }
175  PAPI_get_event_info( events[i], &info );
176  if ( !TESTS_QUIET ) {
177  printf( "PAPI results:\n%20s = ", info.short_descr );
178  printf( LLDFMT, refvalues[i] );
179  printf( "\n" );
180  }
181  }
182  if ( !TESTS_QUIET )
183  printf( "\n" );
184 
185 
186  if ( !TESTS_QUIET ) {
187  printf( "\n\nRelative accuracy:\n" );
188  for ( j = 0; j < nevents; j++ )
189  printf( " Event %.2d", j );
190  printf( "\n" );
191  }
192 
193  for ( j = 0; j < nevents; j++ ) {
194  spread[j] = abs( ( int ) ( refvalues[j] - values[j] ) );
195  if ( values[j] )
196  spread[j] /= ( double ) values[j];
197  if ( !TESTS_QUIET )
198  printf( "%10.3g ", spread[j] );
199  /* Make sure that NaN get counted as errors */
200  if ( spread[j] < MPX_TOLERANCE )
201  i--;
202  else if ( refvalues[j] < MINCOUNTS ) /* Neglect inprecise results with low counts */
203  i--;
204  }
205  if ( !TESTS_QUIET )
206  printf( "\n\n" );
207 
208  if ( i )
209  test_fail( __FILE__, __LINE__, "Values outside threshold", i );
210  else
211  test_pass( __FILE__, NULL, 0 );
212 
213  return 0;
214 }
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
static double dummy3(double x, int iters)
Definition: branches.c:217
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
#define MAXEVENTS
Definition: branches.c:15
#define PAPI_BR_INS
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_NULL
Definition: papi.h:290
return PAPI_OK
Definition: linux-nvml.c:458
volatile double t2
tests_quiet(argc, argv)
#define PAPI_BR_MSP
int PAPI_remove_events(int EventSet, int *Events, int number)
Definition: papi.c:5857
#define printf
Definition: papi_test.h:125
volatile double t1
static double
Definition: fileop.c:1281
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:846
char events[MAX_EVENTS][BUFSIZ]
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:964
#define PAPI_BR_NTK
long long
Definition: iozone.c:19827
#define MINCOUNTS
Definition: branches.c:17
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define SLEEPTIME
Definition: branches.c:16
int PAPI_query_event(int EventCode)
Definition: papi.c:698
#define LLDFMT
Definition: papi_test.h:118
int PAPI_multiplex_init(void)
Definition: papi.c:2926
#define MPX_TOLERANCE
Definition: test_utils.h:15
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
int
Definition: iozone.c:18528
int x
Definition: fileop.c:78
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3277
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
int PAPI_start(int EventSet)
Definition: papi.c:2053
long j
Definition: iozone.c:19135
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
#define PAPI_BR_PRC

Here is the call graph for this function: