PAPI  5.7.0.0
hl_rates.c File Reference
Include dependency graph for hl_rates.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 33 of file hl_rates.c.

34 {
35  int retval, event = 0;
36  float rtime, ptime, mflips, mflops, ipc, epc;
37  long long flpins, flpops, ins, ref, core, evt;
38 
39  double mflips_classic,mflips_swapped;
40  double mflops_classic,mflops_swapped;
41  double ipc_classic,ipc_swapped;
42  double epc_classic,epc_swapped;
43 
44  int quiet;
45 
46  /* Set TESTS_QUIET variable */
47  quiet=tests_quiet( argc, argv );
48 
49  /* Initialize the test matrix */
51 
52  /************************/
53  /* FLIPS */
54  /************************/
55 
56  if (!quiet) {
57  printf( "\n----------------------------------\n" );
58  printf( "PAPI_flips\n");
59  }
60 
61  /* Run flips at start */
62  retval=PAPI_flips(&rtime, &ptime, &flpins, &mflips);
63  if (retval!=PAPI_OK) {
64  if (!quiet) PAPI_perror( "PAPI_flips" );
65  test_skip(__FILE__,__LINE__,"Could not add event",0);
66  }
67 
68  if (!quiet) {
69  printf( "\nStart\n");
70  printf( "real time: %f\n", rtime);
71  printf( "process time: %f\n", ptime);
72  printf( "FP Instructions: %lld\n", flpins);
73  printf( "MFLIPS %f\n", mflips);
74  }
75 
76  /* Be sure we are all zero at beginning */
77  if ((rtime!=0) || (ptime!=0) || (flpins!=0) || (mflips!=0)) {
78  test_fail(__FILE__,__LINE__,"Not initialized to zero",0);
79  }
80 
81  // Flips classic
83  if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips) != PAPI_OK )
84  PAPI_perror( "PAPI_flips" );
85 
86  if (!quiet) {
87  printf( "\nClassic\n");
88  printf( "real time: %f\n", rtime);
89  printf( "process time: %f\n", ptime);
90  printf( "FP Instructions: %lld\n", flpins);
91  printf( "MFLIPS %f\n", mflips);
92  }
93  mflips_classic=mflips;
94 
95  // Flips swapped
97  if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips) != PAPI_OK )
98  PAPI_perror( "PAPI_flips" );
99 
100  if (!quiet) {
101  printf( "\nSwapped\n");
102  printf( "real time: %f\n", rtime);
103  printf( "process time: %f\n", ptime);
104  printf( "FP Instructions: %lld\n", flpins);
105  printf( "MFLIPS %f\n", mflips);
106  }
107  mflips_swapped=mflips;
108 
109  // turn off flips
110  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK ) {
111  PAPI_perror( "PAPI_stop_counters" );
112  }
113 
114 
115  /************************/
116  /* FLOPS */
117  /************************/
118 
119  if (!quiet) {
120  printf( "\n----------------------------------\n" );
121  printf( "PAPI_flops\n");
122  }
123 
124  // Start flops
125  if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops) != PAPI_OK ) {
126  PAPI_perror( "PAPI_flops" );
127  }
128 
129  if (!quiet) {
130  printf( "\nStart\n");
131  printf( "real time: %f\n", rtime);
132  printf( "process time: %f\n", ptime);
133  printf( "FP Operations: %lld\n", flpops);
134  printf( "MFLOPS %f\n", mflops);
135  }
136 
137  /* Be sure we are all zero at beginning */
138  if ((rtime!=0) || (ptime!=0) || (flpops!=0) || (mflops!=0)) {
139  test_fail(__FILE__,__LINE__,"Not initialized to zero",0);
140  }
141 
142  // Classic flops
144  if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops) != PAPI_OK )
145  PAPI_perror( "PAPI_flops" );
146 
147  if (!quiet) {
148  printf( "\nClassic\n");
149  printf( "real time: %f\n", rtime);
150  printf( "process time: %f\n", ptime);
151  printf( "FP Operations: %lld\n", flpops);
152  printf( "MFLOPS %f\n", mflops);
153  }
154  mflops_classic=mflops;
155 
156  // Swapped flops
158  if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops) != PAPI_OK )
159  PAPI_perror( "PAPI_flops" );
160 
161  if (!quiet) {
162  printf( "\nSwapped\n");
163  printf( "real time: %f\n", rtime);
164  printf( "process time: %f\n", ptime);
165  printf( "FP Operations: %lld\n", flpops);
166  printf( "MFLOPS %f\n", mflops);
167  }
168  mflops_swapped=mflops;
169 
170  // turn off flops
171  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK ) {
172  PAPI_perror( "PAPI_stop_counters" );
173  }
174 
175 
176  /************************/
177  /* IPC */
178  /************************/
179 
180  if (!quiet) {
181  printf( "\n----------------------------------\n" );
182  printf( "PAPI_ipc\n");
183  }
184 
185  // Start ipc
186  if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc) != PAPI_OK )
187  PAPI_perror( "PAPI_ipc" );
188 
189  if (!quiet) {
190  printf( "\nStart\n");
191  printf( "real time: %f\n", rtime);
192  printf( "process time: %f\n", ptime);
193  printf( "Instructions: %lld\n", ins);
194  printf( "IPC %f\n", ipc);
195  }
196 
197  /* Be sure we are all zero at beginning */
198  if ((rtime!=0) || (ptime!=0) || (ins!=0) || (ipc!=0)) {
199  test_fail(__FILE__,__LINE__,"Not initialized to zero",0);
200  }
201 
202  // Classic ipc
204  if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc) != PAPI_OK )
205  PAPI_perror( "PAPI_ipc" );
206 
207  if (!quiet) {
208  printf( "\nClassic\n");
209  printf( "real time: %f\n", rtime);
210  printf( "process time: %f\n", ptime);
211  printf( "Instructions: %lld\n", ins);
212  printf( "IPC %f\n", ipc);
213  }
214  ipc_classic=ipc;
215 
216  // Swapped ipc
218  if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc) != PAPI_OK )
219  PAPI_perror( "PAPI_ipc" );
220 
221  if (!quiet) {
222  printf( "\nSwapped\n");
223  printf( "real time: %f\n", rtime);
224  printf( "process time: %f\n", ptime);
225  printf( "Instructions: %lld\n", ins);
226  printf( "IPC %f\n", ipc);
227  }
228  ipc_swapped=ipc;
229 
230  // turn off ipc
231  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK ) {
232  PAPI_perror( "PAPI_stop_counters" );
233  }
234 
235 
236  /************************/
237  /* EPC */
238  /************************/
239 
240  if (!quiet) {
241  printf( "\n----------------------------------\n" );
242  printf( "PAPI_epc\n");
243  }
244 
245  /* This unfortunately conflicts a bit with the TESTS_QUIET */
246  /* command line paramater nonsense. */
247 
248  if ( argc >= 2) {
249  retval = PAPI_event_name_to_code( argv[1], &event );
250  if (retval != PAPI_OK) {
251  if (!quiet) printf("Can't find %s; Using PAPI_TOT_INS\n", argv[1]);
252  event = PAPI_TOT_INS;
253  } else {
254  if (!quiet) printf("Using event %s\n", argv[1]);
255  }
256  }
257 
258  // Start epc
259  if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc) != PAPI_OK )
260  PAPI_perror( "PAPI_epc" );
261 
262  if (!quiet) {
263  printf( "\nStart\n");
264  printf( "real time: %f\n", rtime);
265  printf( "process time: %f\n", ptime);
266  printf( "Ref Cycles: %lld\n", ref);
267  printf( "Core Cycles: %lld\n", core);
268  printf( "Events: %lld\n", evt);
269  printf( "EPC: %f\n", epc);
270  }
271 
272  /* Be sure we are all zero at beginning */
273  if ((rtime!=0) || (ptime!=0) || (ref!=0) || (core!=0)
274  || (evt!=0) || (epc!=0)) {
275  test_fail(__FILE__,__LINE__,"Not initialized to zero",0);
276  }
277 
278  // Classic epc
280  if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc) != PAPI_OK )
281  PAPI_perror( "PAPI_epc" );
282 
283  if (!quiet) {
284  printf( "\nClassic\n");
285  printf( "real time: %f\n", rtime);
286  printf( "process time: %f\n", ptime);
287  printf( "Ref Cycles: %lld\n", ref);
288  printf( "Core Cycles: %lld\n", core);
289  printf( "Events: %lld\n", evt);
290  printf( "EPC: %f\n", epc);
291  }
292  epc_classic=epc;
293 
294  // Swapped epc
296  if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc) != PAPI_OK ) {
297  PAPI_perror( "PAPI_epc" );
298  }
299 
300  if (!quiet) {
301  printf( "\nSwapped\n");
302  printf( "real time: %f\n", rtime);
303  printf( "process time: %f\n", ptime);
304  printf( "Ref Cycles: %lld\n", ref);
305  printf( "Core Cycles: %lld\n", core);
306  printf( "Events: %lld\n", evt);
307  printf( "EPC: %f\n", epc);
308  }
309  epc_swapped=epc;
310 
311  // turn off epc
312  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK ) {
313  PAPI_perror( "PAPI_stop_counters" );
314  }
315 
316  if (!quiet) {
317  printf( "\n----------------------------------\n" );
318  }
319 
320  /* Validate */
321  if (mflips_swapped<mflips_classic) {
322  test_fail(__FILE__,__LINE__,"FLIPS should be better when swapped",0);
323  }
324  if (mflops_swapped<mflops_classic) {
325  test_fail(__FILE__,__LINE__,"FLOPS should be better when swapped",0);
326  }
327  if (ipc_swapped<ipc_classic) {
328  test_fail(__FILE__,__LINE__,"IPC should be better when swapped",0);
329  }
330  if (epc_swapped<epc_classic) {
331  test_fail(__FILE__,__LINE__,"EPC should be better when swapped",0);
332  }
333 
334  test_pass( __FILE__ );
335 
336  return 0;
337 }
#define PAPI_OK
Definition: fpapi.h:105
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_ipc(float *rtime, float *ptime, long long *ins, float *ipc)
Definition: papi_hl.c:320
int PAPI_flops(float *rtime, float *ptime, long long *flpops, float *mflops)
Definition: papi_hl.c:263
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
int retval
Definition: zero_fork.c:53
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_flips(float *rtime, float *ptime, long long *flpins, float *mflips)
Definition: papi_hl.c:204
int PAPI_epc(int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc)
Definition: papi_hl.c:387
float flops_float_swapped_matrix_matrix_multiply(void)
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:807
#define PAPI_TOT_INS
Definition: fpapi.h:186
int quiet
Definition: rapl_overflow.c:18
int flops_float_init_matrix(void)
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
void PAPI_perror(const char *msg)
Definition: papi.c:4653
float flops_float_matrix_matrix_multiply(void)
Here is the call graph for this function: