PAPI 7.1.0.0
Loading...
Searching...
No Matches
low-level.c File Reference
Include dependency graph for low-level.c:

Go to the source code of this file.

Macros

#define NUM_EVENTS   2
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ NUM_EVENTS

#define NUM_EVENTS   2

Definition at line 30 of file low-level.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file low-level.c.

34{
35 int retval;
37 int Events[NUM_EVENTS];
38 int EventSet = PAPI_NULL;
39 int quiet;
40
41 /* Set TESTS_QUIET variable */
42 quiet=tests_quiet( argc, argv );
43
45 if (retval != PAPI_VER_CURRENT ) {
46 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
47 }
48
49 /* query and set up the right events to monitor */
51 Events[0] = PAPI_FP_INS;
52 Events[1] = PAPI_TOT_CYC;
53 } else {
54 Events[0] = PAPI_TOT_INS;
55 Events[1] = PAPI_TOT_CYC;
56 }
57
59 if (retval != PAPI_OK ) {
60 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
61 }
62
63 retval = PAPI_add_events( EventSet, ( int * ) Events, NUM_EVENTS );
64 if (retval < PAPI_OK ) {
65 if (!quiet) printf("Trouble adding events\n");
66 test_skip( __FILE__, __LINE__, "PAPI_add_events", retval );
67 }
68
69 if ( !quiet ) {
70 printf( "\n Incorrect usage of read and accum.\n" );
71 printf( " Some cycles are counted twice\n" );
72 }
73 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
74 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
75
76 /* Loop 1 */
78
79 if ( ( retval = PAPI_read( EventSet, values ) ) != PAPI_OK )
80 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
81
82 if ( !quiet )
83 printf( TWO12, values[0], values[1], "(Counters continuing...)\n" );
84
85 /* Loop 2 */
87
88 /* Using PAPI_accum here is incorrect. The result is that Loop 1 *
89 * is being counted twice */
90 if ( ( retval = PAPI_accum( EventSet, values ) ) != PAPI_OK )
91 test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
92
93 if ( !quiet )
94 printf( TWO12, values[0], values[1], "(Counters being accumulated)\n" );
95
96 /* Loop 3 */
98
99 if ( ( retval = PAPI_stop( EventSet, dummyvalues ) ) != PAPI_OK )
100 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
101
102 if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK )
103 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
104
105 if ( !quiet ) {
106 printf( TWO12, dummyvalues[0], dummyvalues[1],
107 "(Reading stopped counters)\n" );
108
109 printf( TWO12, values[0], values[1], "" );
110
111 printf( "\n Incorrect usage of read and accum.\n" );
112 printf( " Another incorrect use\n" );
113 }
114 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
115 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
116
117 /* Loop 1 */
119
120 if ( ( retval = PAPI_read( EventSet, values ) ) != PAPI_OK )
121 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
122
123 if ( !quiet )
124 printf( TWO12, values[0], values[1], "(Counters continuing...)\n" );
125
126 /* Loop 2 */
127 /* Code that should not be counted */
129
130 if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK )
131 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
132
133 if ( !quiet )
134 printf( TWO12, dummyvalues[0], dummyvalues[1],
135 "(Intermediate counts...)\n" );
136
137 /* Loop 3 */
139
140 /* Since PAPI_read does not reset the counters it's use above after *
141 * loop 2 is incorrect. Instead Loop1 will in effect be counted twice. *
142 * and the counts in loop 2 are included in the total counts */
143 if ( ( retval = PAPI_accum( EventSet, values ) ) != PAPI_OK )
144 test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
145 if ( !quiet )
146 printf( TWO12, values[0], values[1], "" );
147
148 if ( ( retval = PAPI_stop( EventSet, dummyvalues ) ) != PAPI_OK )
149 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
150
151 if ( !quiet ) {
152 printf( "\n Correct usage of read and accum.\n" );
153 printf( " PAPI_reset and PAPI_accum used to skip counting\n" );
154 printf( " a section of the code.\n" );
155 }
156 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
157 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
158
160
161 if ( ( retval = PAPI_read( EventSet, values ) ) != PAPI_OK )
162 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
163 if ( !quiet )
164 printf( TWO12, values[0], values[1], "(Counters continuing)\n" );
165
166 /* Code that should not be counted */
168
169 if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
170 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
171
172 if ( !quiet )
173 printf( "%12s %12s (Counters reset)\n", "", "" );
174
176
177 if ( ( retval = PAPI_accum( EventSet, values ) ) != PAPI_OK )
178 test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
179
180 if ( !quiet )
181 printf( TWO12, values[0], values[1], "" );
182
183 if ( !quiet ) {
184 printf( "----------------------------------\n" );
185 printf( "Verification: The last line in each experiment should be\n" );
186 printf( "approximately twice the value of the first line.\n" );
187 printf
188 ( "The third case illustrates one possible way to accomplish this.\n" );
189 }
190 test_pass( __FILE__ );
191
192 return 0;
193}
Accumulate and reset counters in an EventSet.
add multiple PAPI presets or native hardware events to an event set
Create a new empty PAPI EventSet.
initialize the PAPI library.
Query if PAPI event exists.
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.
#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_FP_INS
Definition: f90papi.h:366
#define PAPI_TOT_INS
Definition: f90papi.h:317
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define NUM_EVENTS
Definition: low-level.c:30
void do_flops(int n)
Definition: multiplex.c:23
long long dummyvalues[2]
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
#define TWO12
Definition: papi_test.h:103
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
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: