PAPI 7.1.0.0
Loading...
Searching...
No Matches
reset_multiplex.c File Reference
Include dependency graph for reset_multiplex.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 17 of file reset_multiplex.c.

18{
19 int retval, num_tests = 9, num_events, tmp, i;
20 long long **values;
21 int EventSet = PAPI_NULL;
22 int PAPI_event, mask;
23 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_2MAX_STR_LEN];
24 int quiet;
25
26 /* Set TESTS_QUIET variable */
27 quiet = tests_quiet( argc, argv );
28
29 /* Init the PAPI library */
31 if ( retval != PAPI_VER_CURRENT ) {
32 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33 }
34
36 if ( retval == PAPI_ENOSUPP) {
37 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
38 }
39 else if ( retval != PAPI_OK ) {
40 test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
41 }
42
43
44 /* add PAPI_TOT_CYC and one of the events in
45 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
46 depending on the availability of the event
47 on the platform */
49
50 /* Set multiplexing on the eventset */
51
53 if ( retval != PAPI_OK) {
54 test_fail(__FILE__, __LINE__, "Setting multiplex", retval);
55 }
56
58 if ( retval != PAPI_OK ) {
59 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
60 }
61 sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
62
64
65 /*===== Test 1: Start/Stop =======================*/
66
68 if ( retval != PAPI_OK ) {
69 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
70 }
71
73
75 if ( retval != PAPI_OK ) {
76 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
77 }
78
79 /*===== Test 2 Start/Stop =======================*/
80
82 if ( retval != PAPI_OK ) {
83 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
84 }
85
87
89 if ( retval != PAPI_OK ) {
90 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
91 }
92
93 /*===== Test 3: Reset/Start/Stop =======================*/
94
96 if ( retval != PAPI_OK ) {
97 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
98 }
99
101 if ( retval != PAPI_OK ) {
102 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
103 }
104
106
108 if ( retval != PAPI_OK ) {
109 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
110 }
111
112 /*===== Test 4: Start/Read =======================*/
113
115 if ( retval != PAPI_OK ) {
116 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
117 }
118
119 do_flops( NUM_FLOPS / 2 );
120
122 if ( retval != PAPI_OK ) {
123 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
124 }
125
126 /*===== Test 5: Read =======================*/
127
128 do_flops( NUM_FLOPS / 2 );
129
131 if ( retval != PAPI_OK ) {
132 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
133 }
134
135 /*===== Test 6: Read/Accum =======================*/
136
137 do_flops( NUM_FLOPS / 2 );
138
140 if ( retval != PAPI_OK ) {
141 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
142 }
143
145
146 if ( retval != PAPI_OK ) {
147 test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
148 }
149
150 /*===== Test 7: Read =======================*/
151
152 do_flops( NUM_FLOPS / 2 );
153
155 if ( retval != PAPI_OK ) {
156 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
157 }
158
159 /*===== Test 8 Reset/Stop =======================*/
161 if ( retval != PAPI_OK ) {
162 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
163 }
164
165 do_flops( NUM_FLOPS / 2 );
166
168 if ( retval != PAPI_OK ) {
169 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
170 }
171
172 /*===== Test 9: Reset/Read =======================*/
174 if ( retval != PAPI_OK ) {
175 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
176 }
177
179 if ( retval != PAPI_OK ) {
180 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
181 }
182
184
185 if (!quiet) {
186 printf( "Test case: Start/Stop/Read/Accum/Reset.\n" );
187 printf( "----------------------------------------------------------------\n" );
188 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
189 printf( "Default domain is: %d (%s)\n", tmp,
191 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
192 printf( "Default granularity is: %d (%s)\n", tmp,
194 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
195 printf( "-------------------------------------------------------------------------\n" );
196
197 sprintf( add_event_str, "%s:", event_name );
198 printf( " PAPI_TOT_CYC %s\n", event_name );
199 printf( "1. start,ops,stop %10lld %10lld\n", values[0][0],
200 values[0][1] );
201 printf( "2. start,ops,stop %10lld %10lld\n", values[1][0],
202 values[1][1] );
203 printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0],
204 values[2][1] );
205 printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0],
206 values[3][1] );
207 printf( "5. ops/2,read %10lld %10lld\n", values[4][0],
208 values[4][1] );
209 printf( "6. ops/2,accum %10lld %10lld\n", values[5][0],
210 values[5][1] );
211 printf( "7. ops/2,read %10lld %10lld\n", values[6][0],
212 values[6][1] );
213 printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0],
214 values[7][1] );
215 printf( "9. reset,read %10lld %10lld\n", values[8][0],
216 values[8][1] );
217 printf( "-------------------------------------------------------------------------\n" );
218 printf( "Verification:\n" );
219 printf( "Row 1 approximately equals rows 2 and 3 \n" );
220 printf( "Row 4 approximately equals 1/2 of row 3\n" );
221 printf( "Row 5 approximately equals twice row 4\n" );
222 printf( "Row 6 approximately equals 6 times row 4\n" );
223 printf( "Rows 7 and 8 approximately equal row 4\n" );
224 printf( "Row 9 equals 0\n" );
225 printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
226 100.0 * ( float ) values[0][0] / ( float ) values[1][0] );
227 printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
228 100.0 * ( float ) values[0][1] / ( float ) values[1][1] );
229 }
230
231 for ( i = 0; i <= 1; i++ ) {
232 if ( !approx_equals
233 ( ( double ) values[0][i], ( double ) values[1][i] ) )
234 test_fail( __FILE__, __LINE__,
235 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
236 if ( !approx_equals
237 ( ( double ) values[1][i], ( double ) values[2][i] ) )
238 test_fail( __FILE__, __LINE__,
239 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
240 if ( !approx_equals
241 ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) )
242 test_fail( __FILE__, __LINE__,
243 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
244 if ( !approx_equals
245 ( ( double ) values[2][i], ( double ) values[4][i] ) )
246 test_fail( __FILE__, __LINE__,
247 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
248 if ( !approx_equals
249 ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) )
250 test_fail( __FILE__, __LINE__,
251 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
252 if ( !approx_equals
253 ( ( double ) values[6][i], ( double ) values[3][i] ) )
254 test_fail( __FILE__, __LINE__,
255 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
256 if ( !approx_equals
257 ( ( double ) values[7][i], ( double ) values[3][i] ) )
258 test_fail( __FILE__, __LINE__,
259 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
260 if ( values[8][i] != 0LL )
261 test_fail( __FILE__, __LINE__,
262 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
263 }
264
265 test_pass( __FILE__ );
266
267 return 0;
268}
double tmp
int i
Accumulate and reset counters in an EventSet.
Convert a numeric hardware event code to a name.
Get PAPI library or event set options.
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.
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_2MAX_STR_LEN
Definition: f90papi.h:180
#define PAPI_DEFDOM
Definition: f90papi.h:188
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
int approx_equals(double a, double b)
Definition: test_utils.c:33
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:640
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: