PAPI  5.6.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
 
#define MPX_TOLERANCE   0.20
 
#define NUM_FLOPS   20000000
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define MAXEVENTS   9

Definition at line 21 of file sdsc2.c.

#define MINCOUNTS   100000

Definition at line 23 of file sdsc2.c.

#define MPX_TOLERANCE   0.20

Definition at line 24 of file sdsc2.c.

#define NUM_FLOPS   20000000

Definition at line 25 of file sdsc2.c.

#define REPEATS   5

Definition at line 20 of file sdsc2.c.

#define SLEEPTIME   100

Definition at line 22 of file sdsc2.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file sdsc2.c.

30 {
31  PAPI_event_info_t info;
32  int i, j, retval;
33  int iters = NUM_FLOPS;
34  double x = 1.1, y, dtmp;
35  long long t1, t2;
36  long long values[MAXEVENTS];
37  int sleep_time = SLEEPTIME;
38 #ifdef STARTSTOP
39  long long dummies[MAXEVENTS];
40 #endif
41  double valsample[MAXEVENTS][REPEATS];
42  double valsum[MAXEVENTS];
43  double avg[MAXEVENTS];
44  double spread[MAXEVENTS];
45  int nevents = MAXEVENTS;
46  int eventset = PAPI_NULL;
47  int events[MAXEVENTS];
48  int fails;
49  int quiet;
50 
51  /* Set the quiet variable */
52  quiet = tests_quiet( argc, argv );
53 
54  /* Parse command line */
55  if ( argc > 1 ) {
56  if ( !strcmp( argv[1], "TESTS_QUIET" ) ) {
57  }
58  else {
59  sleep_time = atoi( argv[1] );
60  if ( sleep_time <= 0 )
61  sleep_time = SLEEPTIME;
62  }
63  }
64 
65  events[0] = PAPI_FP_INS;
66  events[1] = PAPI_TOT_INS;
67  events[2] = PAPI_INT_INS;
68  events[3] = PAPI_TOT_CYC;
69  events[4] = PAPI_STL_CCY;
70  events[5] = PAPI_BR_INS;
71  events[6] = PAPI_SR_INS;
72  events[7] = PAPI_LD_INS;
73  events[8] = PAPI_TOT_IIS;
74 
75  for ( i = 0; i < MAXEVENTS; i++ ) {
76  values[i] = 0;
77  valsum[i] = 0;
78  }
79 
80 
81  if ( !quiet ) {
82  printf( "\nAccuracy check of multiplexing routines.\n" );
83  printf( "Investigating the variance of multiplexed measurements.\n\n" );
84  }
85 
87  if (retval != PAPI_VER_CURRENT ) {
88  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
89  }
90 
91 #ifdef MPX
92  retval = PAPI_multiplex_init( );
93  if ( retval != PAPI_OK ) {
94  test_fail( __FILE__, __LINE__,
95  "PAPI multiplex init fail\n", retval );
96  }
97 #endif
98 
99  if ( ( retval = PAPI_create_eventset( &eventset ) ) ) {
100  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
101  }
102 
103 #ifdef MPX
104 
105  /* In Component PAPI, EventSets must be assigned a component index
106  before you can fiddle with their internals.
107  0 is always the cpu component */
108  retval = PAPI_assign_eventset_component( eventset, 0 );
109  if ( retval != PAPI_OK ) {
110  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
111  retval );
112  }
113 
114  if ( ( retval = PAPI_set_multiplex( eventset ) ) ) {
115  if ( retval == PAPI_ENOSUPP) {
116  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
117  }
118  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
119  }
120 #endif
121 
122  /* Iterate through event list and remove those that aren't available */
123  nevents = MAXEVENTS;
124  for ( i = 0; i < nevents; i++ ) {
125  if ( ( retval = PAPI_add_event( eventset, events[i] ) ) ) {
126  for ( j = i; j < MAXEVENTS-1; j++ ) {
127  events[j] = events[j + 1];
128  }
129  nevents--;
130  i--;
131  }
132  }
133 
134  /* Skip test if not enough events available */
135  if ( nevents < 2 ) {
136  test_skip( __FILE__, __LINE__, "Not enough events left...", 0 );
137  }
138 
139  /* Find a reasonable number of iterations (each
140  * event active 20 times) during the measurement
141  */
142 
143  /* Target: 10000 usec/multiplex, 20 repeats */
144  t2 = 10000 * 20 * nevents;
145  if ( t2 > 30e6 ) {
146  test_skip( __FILE__, __LINE__, "This test takes too much time",
147  retval );
148  }
149 
150  /* Measure time of one iteration */
151  t1 = PAPI_get_real_usec( );
152  y = do_flops3( x, iters, 1 );
153  t1 = PAPI_get_real_usec( ) - t1;
154 
155  /* Scale up execution time to match t2 */
156  if ( t2 > t1 ) {
157  iters = iters * ( int ) ( t2 / t1 );
158  }
159  /* Make sure execution time is < 30s per repeated test */
160  else if ( t1 > 30e6 ) {
161  test_skip( __FILE__, __LINE__, "This test takes too much time",
162  retval );
163  }
164 
165  if ( ( retval = PAPI_start( eventset ) ) ) {
166  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
167  }
168 
169  for ( i = 1; i <= REPEATS; i++ ) {
170  x = 1.0;
171 
172 #ifndef STARTSTOP
173  if ( ( retval = PAPI_reset( eventset ) ) )
174  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
175 #else
176  if ( ( retval = PAPI_stop( eventset, dummies ) ) )
177  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
178  if ( ( retval = PAPI_start( eventset ) ) )
179  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
180 #endif
181 
182  if ( !quiet ) {
183  printf( "\nTest %d (of %d):\n", i, REPEATS );
184  }
185 
186  t1 = PAPI_get_real_usec( );
187  y = do_flops3( x, iters, 1 );
188  PAPI_read( eventset, values );
189  t2 = PAPI_get_real_usec( );
190 
191  if ( !quiet ) {
192  printf( "\n(calculated independent of PAPI)\n" );
193  printf( "\tOperations= %.1f Mflop", y * 1e-6 );
194  printf( "\t(%g Mflop/s)\n\n",
195  ( y / ( double ) ( t2 - t1 ) ) );
196  printf( "PAPI measurements:\n" );
197 
198  for ( j = 0; j < nevents; j++ ) {
199  PAPI_get_event_info( events[j], &info );
200  printf( "%20s = ", info.short_descr );
201  printf( "%lld", values[j] );
202  printf( "\n" );
203  }
204  printf( "\n" );
205  }
206 
207  /* Calculate values */
208  for ( j = 0; j < nevents; j++ ) {
209  dtmp = ( double ) values[j];
210  valsum[j] += dtmp;
211  valsample[j][i - 1] = dtmp;
212  }
213  }
214 
215  if ( ( retval = PAPI_stop( eventset, values ) ) )
216  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
217 
218  if ( !quiet ) {
219  printf( "\n\nEstimated variance relative "
220  "to average counts:\n" );
221  for ( j = 0; j < nevents; j++ )
222  printf( " Event %.2d", j );
223  printf( "\n" );
224  }
225 
226  fails = nevents;
227  /* Due to limited precision of floating point cannot really use
228  typical standard deviation compuation for large numbers with
229  very small variations. Instead compute the std devation
230  problems with precision.
231  */
232  for ( j = 0; j < nevents; j++ ) {
233  avg[j] = valsum[j] / REPEATS;
234  spread[j] = 0;
235  for ( i = 0; i < REPEATS; ++i ) {
236  double diff = ( valsample[j][i] - avg[j] );
237  spread[j] += diff * diff;
238  }
239  spread[j] = sqrt( spread[j] / REPEATS ) / avg[j];
240  if ( !quiet )
241  printf( "%9.2g ", spread[j] );
242  /* Make sure that NaN get counted as errors */
243  if ( spread[j] < MPX_TOLERANCE ) {
244  --fails;
245  }
246  /* Neglect inprecise results with low counts */
247  else if ( valsum[j] < MINCOUNTS ) {
248  --fails;
249  }
250  }
251 
252  if ( !quiet ) {
253  printf( "\n\n" );
254  for ( j = 0; j < nevents; j++ ) {
255  PAPI_get_event_info( events[j], &info );
256  printf( "Event %.2d: mean=%10.0f, "
257  "sdev/mean=%7.2g nrpt=%2d -- %s\n",
258  j, avg[j], spread[j],
259  REPEATS, info.short_descr );
260  }
261  printf( "\n\n" );
262  }
263 
264  if ( fails ) {
265  test_fail( __FILE__, __LINE__,
266  "Values outside threshold", fails );
267  }
268 
269  test_pass( __FILE__ );
270 
271  return 0;
272 }
#define MAXEVENTS
Definition: sdsc2.c:21
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define REPEATS
Definition: sdsc2.c:20
#define NUM_FLOPS
Definition: sdsc2.c:25
#define PAPI_TOT_IIS
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
int PAPI_reset(int EventSet)
Definition: papi.c:2459
double do_flops3(double x, int iters, int quiet)
#define PAPI_BR_INS
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:497
#define PAPI_STL_CCY
volatile double t2
volatile double t1
static double
Definition: fileop.c:1281
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char events[MAX_EVENTS][BUFSIZ]
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
long long y
Definition: iozone.c:1335
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
#define PAPI_LD_INS
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:967
#define MINCOUNTS
Definition: sdsc2.c:23
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define MPX_TOLERANCE
Definition: sdsc2.c:24
#define PAPI_INT_INS
int PAPI_multiplex_init(void)
Definition: papi.c:2982
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int
Definition: iozone.c:18528
int x
Definition: fileop.c:78
#define SLEEPTIME
Definition: sdsc2.c:22
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3333
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:225
#define PAPI_FP_INS

Here is the call graph for this function: