PAPI 7.1.0.0
Loading...
Searching...
No Matches
reset.c
Go to the documentation of this file.
1/* This file performs the following test: start, read, stop and again functionality
2
3 - It attempts to use the following three counters. It may use less depending on
4 hardware counter resource limitations. These are counted in the default counting
5 domain and default granularity, depending on the platform. Usually this is
6 the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
7 + PAPI_FP_INS or PAPI_TOT_INS if PAPI_FP_INS doesn't exist
8 + PAPI_TOT_CYC
9
10 1
11 - Start counters
12 - Do flops
13 - Stop counters
14
15 2
16 - Start counters
17 - Do flops
18 - Stop counters (should duplicate above)
19
20 3
21 - Reset counters (should be redundant if stop works properly)
22 - Start counters
23 - Do flops
24 - Stop counters
25
26 4
27 - Start counters
28 - Do flops/2
29 - Read counters (flops/2;counters keep counting)
30
31 5
32 - Do flops/2
33 - Read counters (2flops/2; counters keep counting)
34
35 6
36 - Do flops/2
37 - Read counters (3*flops/2; counters keep counting)
38 - Accum counters (2*(3*flops.2); counters clear and counting)
39
40 7
41 - Do flops/2
42 - Read counters (flops/2; counters keep counting)
43
44 8
45 - Reset (counters set to zero; still counting)
46 - Stop counters (flops/2; counters stopped)
47
48 9
49 - Reset (counters set to zero; still counting)
50 - Do flops/2
51 - Stop counters (flops/2; counters stopped)
52
53 9
54 - Reset (counters set to zero and stopped)
55 - Read counters (should be zero)
56*/
57
58#include <stdio.h>
59
60#include "papi.h"
61#include "papi_test.h"
62
63#include "do_loops.h"
64
65int
66main( int argc, char **argv )
67{
68 int retval, num_tests = 9, num_events, tmp, i;
69 long long **values;
70 int EventSet = PAPI_NULL;
71 int PAPI_event, mask;
72 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_2MAX_STR_LEN];
73 int quiet;
74
75 /* Set TESTS_QUIET variable */
76 quiet = tests_quiet( argc, argv );
77
78 /* Init the PAPI library */
80 if ( retval != PAPI_VER_CURRENT ) {
81 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
82 }
83
84 /* add PAPI_TOT_CYC and one of the events in
85 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
86 depending on the availability of the event
87 on the platform */
89
91 if ( retval != PAPI_OK ) {
92 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
93 }
94 sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
95
97
98 /*===== Test 1: Start/Stop =======================*/
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 2 Start/Stop =======================*/
113
115 if ( retval != PAPI_OK ) {
116 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
117 }
118
120
122 if ( retval != PAPI_OK ) {
123 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
124 }
125
126 /*===== Test 3: Reset/Start/Stop =======================*/
127
129 if ( retval != PAPI_OK ) {
130 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
131 }
132
134 if ( retval != PAPI_OK ) {
135 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
136 }
137
139
141 if ( retval != PAPI_OK ) {
142 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
143 }
144
145 /*===== Test 4: Start/Read =======================*/
146
148 if ( retval != PAPI_OK ) {
149 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
150 }
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 5: Read =======================*/
160
161 do_flops( NUM_FLOPS / 2 );
162
164 if ( retval != PAPI_OK ) {
165 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
166 }
167
168 /*===== Test 6: Read/Accum =======================*/
169
170 do_flops( NUM_FLOPS / 2 );
171
173 if ( retval != PAPI_OK ) {
174 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
175 }
176
178
179 if ( retval != PAPI_OK ) {
180 test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
181 }
182
183 /*===== Test 7: Read =======================*/
184
185 do_flops( NUM_FLOPS / 2 );
186
188 if ( retval != PAPI_OK ) {
189 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
190 }
191
192 /*===== Test 8 Reset/Stop =======================*/
194 if ( retval != PAPI_OK ) {
195 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
196 }
197
198 do_flops( NUM_FLOPS / 2 );
199
201 if ( retval != PAPI_OK ) {
202 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
203 }
204
205 /*===== Test 9: Reset/Read =======================*/
207 if ( retval != PAPI_OK ) {
208 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
209 }
210
212 if ( retval != PAPI_OK ) {
213 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
214 }
215
217
218 if (!quiet) {
219 printf( "Test case: Start/Stop/Read/Accum/Reset.\n" );
220 printf( "----------------------------------------------------------------\n" );
221 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
222 printf( "Default domain is: %d (%s)\n", tmp,
224 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
225 printf( "Default granularity is: %d (%s)\n", tmp,
227 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
228 printf( "-------------------------------------------------------------------------\n" );
229
230 sprintf( add_event_str, "%s:", event_name );
231 printf( " PAPI_TOT_CYC %s\n", event_name );
232 printf( "1. start,ops,stop %10lld %10lld\n", values[0][0],
233 values[0][1] );
234 printf( "2. start,ops,stop %10lld %10lld\n", values[1][0],
235 values[1][1] );
236 printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0],
237 values[2][1] );
238 printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0],
239 values[3][1] );
240 printf( "5. ops/2,read %10lld %10lld\n", values[4][0],
241 values[4][1] );
242 printf( "6. ops/2,accum %10lld %10lld\n", values[5][0],
243 values[5][1] );
244 printf( "7. ops/2,read %10lld %10lld\n", values[6][0],
245 values[6][1] );
246 printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0],
247 values[7][1] );
248 printf( "9. reset,read %10lld %10lld\n", values[8][0],
249 values[8][1] );
250 printf( "-------------------------------------------------------------------------\n" );
251 printf( "Verification:\n" );
252 printf( "Row 1 approximately equals rows 2 and 3 \n" );
253 printf( "Row 4 approximately equals 1/2 of row 3\n" );
254 printf( "Row 5 approximately equals twice row 4\n" );
255 printf( "Row 6 approximately equals 6 times row 4\n" );
256 printf( "Rows 7 and 8 approximately equal row 4\n" );
257 printf( "Row 9 equals 0\n" );
258 printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
259 100.0 * ( float ) values[0][0] / ( float ) values[1][0] );
260 printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
261 100.0 * ( float ) values[0][1] / ( float ) values[1][1] );
262 }
263
264 for ( i = 0; i <= 1; i++ ) {
265 if ( !approx_equals
266 ( ( double ) values[0][i], ( double ) values[1][i] ) )
267 test_fail( __FILE__, __LINE__,
268 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
269 if ( !approx_equals
270 ( ( double ) values[1][i], ( double ) values[2][i] ) )
271 test_fail( __FILE__, __LINE__,
272 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
273 if ( !approx_equals
274 ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) )
275 test_fail( __FILE__, __LINE__,
276 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
277 if ( !approx_equals
278 ( ( double ) values[2][i], ( double ) values[4][i] ) )
279 test_fail( __FILE__, __LINE__,
280 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
281 if ( !approx_equals
282 ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) )
283 test_fail( __FILE__, __LINE__,
284 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
285 if ( !approx_equals
286 ( ( double ) values[6][i], ( double ) values[3][i] ) )
287 test_fail( __FILE__, __LINE__,
288 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
289 if ( !approx_equals
290 ( ( double ) values[7][i], ( double ) values[3][i] ) )
291 test_fail( __FILE__, __LINE__,
292 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
293 if ( values[8][i] != 0LL )
294 test_fail( __FILE__, __LINE__,
295 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
296 }
297
298 test_pass( __FILE__ );
299
300 return 0;
301}
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.
Read hardware counters from an event set.
Reset the hardware event counts in an 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_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
Return codes and api definitions.
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
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int main()
Definition: pernode.c:20
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