PAPI 7.1.0.0
Loading...
Searching...
No Matches
first.c File Reference
Include dependency graph for first.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 34 of file first.c.

35{
36 int retval, num_tests = 5, num_events, tmp;
37 long long **values;
38 int EventSet = PAPI_NULL;
39 char event_name1[]="PAPI_TOT_CYC";
40 char event_name2[]="PAPI_TOT_INS";
41 char add_event_str[PAPI_MAX_STR_LEN];
42 long long min, max;
43 int quiet;
44
45 /* Set TESTS_QUIET variable */
46 quiet = tests_quiet( argc, argv );
47
48 /* Init PAPI library */
50 if ( retval != PAPI_VER_CURRENT ) {
51 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
52 }
53
54 /* create the eventset */
56 if ( retval != PAPI_OK ) {
57 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
58 }
59
60 retval = PAPI_add_named_event( EventSet, event_name1);
61 if ( retval != PAPI_OK ) {
62 if (!quiet) printf("Couldn't add %s\n",event_name1);
63 test_skip(__FILE__,__LINE__,"Couldn't add PAPI_TOT_CYC",0);
64 }
65
66 retval = PAPI_add_named_event( EventSet, event_name2);
67 if ( retval != PAPI_OK ) {
68 if (!quiet) printf("Couldn't add %s\n",event_name2);
69 test_skip(__FILE__,__LINE__,"Couldn't add PAPI_TOT_INS",0);
70 }
71
72 num_events=2;
73
74 sprintf( add_event_str, "PAPI_add_event[%s]", event_name2 );
75
76 /* Allocate space for results */
78
79 /* Start PAPI */
81 if ( retval != PAPI_OK ) {
82 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
83 }
84
85 /* Benchmark code */
87
88 /* read results 0 */
90 if ( retval != PAPI_OK ) {
91 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
92 }
93
94 /* Reset */
96 if ( retval != PAPI_OK ) {
97 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
98 }
99
100 /* Benchmark some more */
102
103 /* Read Results 1 */
105 if ( retval != PAPI_OK ) {
106 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
107 }
108
109 /* Benchmark some more */
111
112 /* Read results 2 */
114 if ( retval != PAPI_OK ) {
115 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
116 }
117
118 /* Benchmark some more */
120
121 /* Read results 3 */
123 if ( retval != PAPI_OK ) {
124 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
125 }
126
127 /* Read results 4 */
129 if ( retval != PAPI_OK ) {
130 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
131 }
132
133 /* remove results. We never stop??? */
136
137 if ( !quiet ) {
138 printf( "Test case 1: Non-overlapping start, stop, read.\n" );
139 printf( "-----------------------------------------------\n" );
140 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
141 printf( "Default domain is: %d (%s)\n", tmp,
143 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
144 printf( "Default granularity is: %d (%s)\n", tmp,
146 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
147 printf( "-------------------------------------------------------------------------\n" );
148
149 printf( "Test type : 1 2 3 4 5\n" );
150 sprintf( add_event_str, "%s:", event_name2 );
151 printf( TAB5, add_event_str,
152 values[0][1], values[1][1], values[2][1],
153 values[3][1], values[4][1] );
154 printf( TAB5, "PAPI_TOT_CYC:",
155 values[0][0], values[1][0], values[2][0],
156 values[3][0], values[4][0] );
157 printf( "-------------------------------------------------------------------------\n" );
158
159 printf( "Verification:\n" );
160 printf( "Row 1 Column 1 at least %d\n", NUM_FLOPS );
161 printf( "%% difference between %s 1 & 2: %.2f\n",
162 add_event_str,
163 100.0 * ( float ) values[0][1] /
164 ( float ) values[1][1] );
165 printf( "%% difference between %s 1 & 2: %.2f\n",
166 "PAPI_TOT_CYC",
167 100.0 * ( float ) values[0][0] /
168 ( float ) values[1][0] );
169 printf( "Column 1 approximately equals column 2\n" );
170 printf( "Column 3 approximately equals 2 * column 2\n" );
171 printf( "Column 4 approximately equals 3 * column 2\n" );
172 printf( "Column 4 exactly equals column 5\n" );
173 }
174
175 /* Validation */
176
177 /* Check cycles constraints */
178
179 min = ( long long ) ( ( double ) values[1][0] * .8 );
180 max = ( long long ) ( ( double ) values[1][0] * 1.2 );
181
182 /* Check constraint Col1=Col2 */
183 if ( values[0][0] > max || values[0][0] < min ) {
184 test_fail( __FILE__, __LINE__, "Cycle Col1!=Col2", 1 );
185 }
186 /* Check constraint col3 == 2*col2 */
187 if ( (values[2][0] > ( 2 * max )) ||
188 (values[2][0] < ( 2 * min )) ) {
189 test_fail( __FILE__, __LINE__, "Cycle Col3!=2*Col2", 1 );
190 }
191 /* Check constraint col4 == 3*col2 */
192 if ( (values[3][0] > ( 3 * max )) ||
193 (values[3][0] < ( 3 * min )) ) {
194 test_fail( __FILE__, __LINE__, "Cycle Col3!=3*Col2", 1 );
195 }
196 /* Check constraint col4 == col5 */
197 if ( values[3][0] != values[4][0] ) {
198 test_fail( __FILE__, __LINE__, "Cycle Col4!=Col5", 1 );
199 }
200
201
202 /* Check FLOP constraints */
203
204 min = ( long long ) ( ( double ) values[1][1] * .9 );
205 max = ( long long ) ( ( double ) values[1][1] * 1.1 );
206
207 /* Check constraint Col1=Col2 */
208 if ( values[0][1] > max || values[0][1] < min ) {
209 test_fail( __FILE__, __LINE__, "FLOP Col1!=Col2", 1 );
210 }
211 /* Check constraint col3 == 2*col2 */
212 if ( (values[2][1] > ( 2 * max )) ||
213 (values[2][1] < ( 2 * min )) ) {
214 test_fail( __FILE__, __LINE__, "FLOP Col3!=2*Col2", 1 );
215 }
216 /* Check constraint col4 == 3*col2 */
217 if ( (values[3][1] > ( 3 * max )) ||
218 (values[3][1] < ( 3 * min )) ) {
219 test_fail( __FILE__, __LINE__, "FLOP Col4!=3*Col2", 1 );
220 }
221 /* Check constraint col4 == col5 */
222 if (values[3][1] != values[4][1]) {
223 test_fail( __FILE__, __LINE__, "FLOP Col4!=Col5", 1 );
224 }
225 /* Check flops are sane */
226 if (values[0][1] < ( long long ) NUM_FLOPS ) {
227 test_fail( __FILE__, __LINE__, "FLOP sanity", 1 );
228 }
229
230 test_pass( __FILE__ );
231
232 return 0;
233
234}
double tmp
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
Get PAPI library or event set options.
initialize the PAPI library.
Read hardware counters from an event set.
removes a named hardware event from a PAPI 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 min(x, y)
Definition: darwin-common.h:4
#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_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
#define TAB5
Definition: papi_test.h:102
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
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
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
long long int long long
Definition: sde_internal.h:85
#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: