PAPI 7.1.0.0
Loading...
Searching...
No Matches
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

◆ MAXEVENTS

#define MAXEVENTS   9

Definition at line 21 of file sdsc2.c.

◆ MINCOUNTS

#define MINCOUNTS   100000

Definition at line 23 of file sdsc2.c.

◆ MPX_TOLERANCE

#define MPX_TOLERANCE   0.20

Definition at line 24 of file sdsc2.c.

◆ NUM_FLOPS

#define NUM_FLOPS   20000000

Definition at line 25 of file sdsc2.c.

◆ REPEATS

#define REPEATS   5

Definition at line 20 of file sdsc2.c.

◆ SLEEPTIME

#define SLEEPTIME   100

Definition at line 22 of file sdsc2.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file sdsc2.c.

30{
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
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
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 */
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
187 y = do_flops3( x, iters, 1 );
188 PAPI_read( eventset, values );
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}
int i
static struct timeval t1 t2
Definition: benchSANVML.c:117
add PAPI preset or native hardware event to an event set
Assign a component index to an existing but empty EventSet.
Create a new empty PAPI EventSet.
Get the event's name and description info.
get real time counter value in microseconds
initialize the PAPI library.
Initialize multiplex support in the PAPI library.
Read hardware counters from an event set.
Reset the hardware event counts in an event set.
Convert a standard event set to a multiplexed event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
volatile double t1
double do_flops3(double x, int iters, int quiet)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_BR_INS
Definition: f90papi.h:300
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_FP_INS
Definition: f90papi.h:366
#define PAPI_STL_CCY
Definition: f90papi.h:373
#define PAPI_SR_INS
Definition: f90papi.h:357
#define PAPI_INT_INS
Definition: f90papi.h:391
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_TOT_IIS
Definition: f90papi.h:379
#define PAPI_LD_INS
Definition: f90papi.h:292
char events[MAX_EVENTS][BUFSIZ]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
#define MAXEVENTS
Definition: sdsc2.c:21
#define MINCOUNTS
Definition: sdsc2.c:23
#define MPX_TOLERANCE
Definition: sdsc2.c:24
#define NUM_FLOPS
Definition: sdsc2.c:25
#define SLEEPTIME
Definition: sdsc2.c:22
#define REPEATS
Definition: sdsc2.c:20
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:961
volatile double y
volatile double x
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: