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

Go to the source code of this file.

Macros

#define REPEATS   5
 
#define MAXEVENTS   9
 
#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   9

Definition at line 17 of file sdsc2.c.

#define MINCOUNTS   100000

Definition at line 19 of file sdsc2.c.

#define REPEATS   5

Definition at line 16 of file sdsc2.c.

#define SLEEPTIME   100

Definition at line 18 of file sdsc2.c.

Function Documentation

static double dummy3 ( double  x,
int  iters 
)
static

Definition at line 233 of file sdsc2.c.

234 {
235  int i;
236  double w, y, z, a, b, c, d, e, f, g, h;
237  double one;
238  one = 1.0;
239  w = x;
240  y = x;
241  z = x;
242  a = x;
243  b = x;
244  c = x;
245  d = x;
246  e = x;
247  f = x;
248  g = x;
249  h = x;
250  for ( i = 1; i <= iters; i++ ) {
251  w = w * 1.000000000001 + one;
252  y = y * 1.000000000002 + one;
253  z = z * 1.000000000003 + one;
254  a = a * 1.000000000004 + one;
255  b = b * 1.000000000005 + one;
256  c = c * 0.999999999999 + one;
257  d = d * 0.999999999998 + one;
258  e = e * 0.999999999997 + one;
259  f = f * 0.999999999996 + one;
260  g = h * 0.999999999995 + one;
261  h = h * 1.000000000006 + one;
262  }
263  return 2.0 * ( a + b + c + d + e + f + w + x + y + z + g + h );
264 }
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 24 of file sdsc2.c.

25 {
26  PAPI_event_info_t info;
27  int i, j, retval;
28  int iters = NUM_FLOPS;
29  double x = 1.1, y, dtmp;
30  long long t1, t2;
31  long long values[MAXEVENTS];
32  int sleep_time = SLEEPTIME;
33 #ifdef STARTSTOP
34  long long dummies[MAXEVENTS];
35 #endif
36  double valsample[MAXEVENTS][REPEATS];
37  double valsum[MAXEVENTS];
38  double avg[MAXEVENTS];
39  double spread[MAXEVENTS];
40  int nevents = MAXEVENTS;
41  int eventset = PAPI_NULL;
42  int events[MAXEVENTS];
43  int fails;
44 
45  events[0] = PAPI_FP_INS;
46  events[1] = PAPI_TOT_INS;
47  events[2] = PAPI_INT_INS;
48  events[3] = PAPI_TOT_CYC;
49  events[4] = PAPI_STL_CCY;
50  events[5] = PAPI_BR_INS;
51  events[6] = PAPI_SR_INS;
52  events[7] = PAPI_LD_INS;
53  events[8] = PAPI_TOT_IIS;
54 
55  for ( i = 0; i < MAXEVENTS; i++ ) {
56  values[i] = 0;
57  valsum[i] = 0;
58  }
59 
60  if ( argc > 1 ) {
61  if ( !strcmp( argv[1], "TESTS_QUIET" ) )
62  tests_quiet( argc, argv );
63  else {
64  sleep_time = atoi( argv[1] );
65  if ( sleep_time <= 0 )
66  sleep_time = SLEEPTIME;
67  }
68  }
69 
70  if ( !TESTS_QUIET ) {
71  printf( "\nAccuracy check of multiplexing routines.\n" );
72  printf( "Investigating the variance of multiplexed measurements.\n\n" );
73  }
74 
75  if ( ( retval =
77  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
78 
79 #ifdef MPX
80  init_multiplex( );
81 #endif
82 
83  if ( ( retval = PAPI_create_eventset( &eventset ) ) )
84  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
85 #ifdef MPX
86 
87  /* In Component PAPI, EventSets must be assigned a component index
88  before you can fiddle with their internals.
89  0 is always the cpu component */
90  retval = PAPI_assign_eventset_component( eventset, 0 );
91  if ( retval != PAPI_OK )
92  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
93  retval );
94 
95  if ( ( retval = PAPI_set_multiplex( eventset ) ) ) {
96  if ( retval == PAPI_ENOSUPP) {
97  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
98  }
99 
100  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
101  }
102 #endif
103 
104  /* What does this code even do? */
105  nevents = MAXEVENTS;
106  for ( i = 0; i < nevents; i++ ) {
107  if ( ( retval = PAPI_add_event( eventset, events[i] ) ) ) {
108  for ( j = i; j < MAXEVENTS-1; j++ ) {
109  events[j] = events[j + 1];
110  }
111  nevents--;
112  i--;
113  }
114  }
115  if ( nevents < 2 )
116  test_skip( __FILE__, __LINE__, "Not enough events left...", 0 );
117 
118  /* Find a reasonable number of iterations (each
119  * event active 20 times) during the measurement
120  */
121  t2 = 10000 * 20 * nevents; /* Target: 10000 usec/multiplex, 20 repeats */
122  if ( t2 > 30e6 )
123  test_skip( __FILE__, __LINE__, "This test takes too much time",
124  retval );
125 
126  /* Measure one run */
127  t1 = PAPI_get_real_usec( );
128  y = dummy3( x, iters );
129  t1 = PAPI_get_real_usec( ) - t1;
130 
131  if ( t2 > t1 ) /* Scale up execution time to match t2 */
132  iters = iters * ( int ) ( t2 / t1 );
133  else if ( t1 > 30e6 ) /* Make sure execution time is < 30s per repeated test */
134  test_skip( __FILE__, __LINE__, "This test takes too much time",
135  retval );
136 
137  if ( ( retval = PAPI_start( eventset ) ) )
138  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
139 
140  for ( i = 1; i <= REPEATS; i++ ) {
141  x = 1.0;
142 
143 #ifndef STARTSTOP
144  if ( ( retval = PAPI_reset( eventset ) ) )
145  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
146 #else
147  if ( ( retval = PAPI_stop( eventset, dummies ) ) )
148  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
149  if ( ( retval = PAPI_start( eventset ) ) )
150  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
151 #endif
152 
153  if ( !TESTS_QUIET )
154  printf( "\nTest %d (of %d):\n", i, REPEATS );
155  t1 = PAPI_get_real_usec( );
156  y = dummy3( x, iters );
157  PAPI_read( eventset, values );
158  t2 = PAPI_get_real_usec( );
159 
160  if ( !TESTS_QUIET ) {
161  printf( "\n(calculated independent of PAPI)\n" );
162  printf( "\tOperations= %.1f Mflop", y * 1e-6 );
163  printf( "\t(%g Mflop/s)\n\n", ( y / ( double ) ( t2 - t1 ) ) );
164  printf( "PAPI measurements:\n" );
165  }
166  for ( j = 0; j < nevents; j++ ) {
167  PAPI_get_event_info( events[j], &info );
168  if ( !TESTS_QUIET ) {
169  printf( "%20s = ", info.short_descr );
170  printf( LLDFMT, values[j] );
171  printf( "\n" );
172  }
173  dtmp = ( double ) values[j];
174  valsum[j] += dtmp;
175  valsample[j][i - 1] = dtmp;
176  }
177  if ( !TESTS_QUIET )
178  printf( "\n" );
179  }
180 
181  if ( ( retval = PAPI_stop( eventset, values ) ) )
182  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
183 
184  if ( !TESTS_QUIET ) {
185  printf( "\n\nEstimated variance relative to average counts:\n" );
186  for ( j = 0; j < nevents; j++ )
187  printf( " Event %.2d", j );
188  printf( "\n" );
189  }
190 
191  fails = nevents;
192  /* Due to limited precision of floating point cannot really use
193  typical standard deviation compuation for large numbers with
194  very small variations. Instead compute the std devation
195  problems with precision.
196  */
197  for ( j = 0; j < nevents; j++ ) {
198  avg[j] = valsum[j] / REPEATS;
199  spread[j] = 0;
200  for ( i = 0; i < REPEATS; ++i ) {
201  double diff = ( valsample[j][i] - avg[j] );
202  spread[j] += diff * diff;
203  }
204  spread[j] = sqrt( spread[j] / REPEATS ) / avg[j];
205  if ( !TESTS_QUIET )
206  printf( "%9.2g ", spread[j] );
207  /* Make sure that NaN get counted as errors */
208  if ( spread[j] < MPX_TOLERANCE )
209  --fails;
210  else if ( valsum[j] < MINCOUNTS ) /* Neglect inprecise results with low counts */
211  --fails;
212  }
213 
214  if ( !TESTS_QUIET ) {
215  printf( "\n\n" );
216  for ( j = 0; j < nevents; j++ ) {
217  PAPI_get_event_info( events[j], &info );
218  printf( "Event %.2d: mean=%10.0f, sdev/mean=%7.2g nrpt=%2d -- %s\n",
219  j, avg[j], spread[j], REPEATS, info.short_descr );
220  }
221  printf( "\n\n" );
222  }
223 
224  if ( fails )
225  test_fail( __FILE__, __LINE__, "Values outside threshold", fails );
226  else
227  test_pass( __FILE__, NULL, 0 );
228 
229  return 0;
230 }
#define MAXEVENTS
Definition: sdsc2.c:17
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
#define REPEATS
Definition: sdsc2.c:16
#define PAPI_TOT_IIS
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
int PAPI_reset(int EventSet)
Definition: papi.c:2403
#define PAPI_BR_INS
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_ENOSUPP
Definition: papi.h:269
#define PAPI_NULL
Definition: papi.h:290
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_STL_CCY
volatile double t2
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
volatile double t1
void init_multiplex(void)
Definition: test_utils.c:892
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
#define PAPI_TOT_CYC
#define PAPI_LD_INS
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:964
#define MINCOUNTS
Definition: sdsc2.c:19
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1485
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define PAPI_INT_INS
#define LLDFMT
Definition: papi_test.h:118
#define MPX_TOLERANCE
Definition: test_utils.h:15
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
int
Definition: iozone.c:18528
static double dummy3(double x, int iters)
Definition: sdsc2.c:233
int x
Definition: fileop.c:78
#define SLEEPTIME
Definition: sdsc2.c:18
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3277
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
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
#define PAPI_SR_INS
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
#define PAPI_FP_INS

Here is the call graph for this function: