PAPI  5.7.0.0
PAPI_flops.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * This example demonstrates the usage of the high level function PAPI_flops *
3  * which measures the number of floating point operations executed and the *
4  * MegaFlop rate(defined as the number of floating point operations per *
5  * microsecond). To use PAPI_flops you need to have floating point operations*
6  * event supported by the platform. *
7  *****************************************************************************/
8 
9 /*****************************************************************************
10  * The first call to PAPI_flops initializes the PAPI library, set up the *
11  * counters to monitor PAPI_FP_OPS and PAPI_TOT_CYC events, and start the *
12  * counters. Subsequent calls will read the counters and return total real *
13  * time, total process time, total floating point operations, and the *
14  * Mflops/s rate since the last call to PAPI_flops. *
15  *****************************************************************************/
16 
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "papi.h"
21 
22 
24 {
25  float real_time, proc_time,mflops;
26  long long flpops;
27  float ireal_time, iproc_time, imflops;
28  long long iflpops;
29  int retval;
30 
31  /***********************************************************************
32  * if PAPI_FP_OPS is a derived event in your platform, then your *
33  * platform must have at least three counters to support PAPI_flops, *
34  * because PAPI needs one counter to cycles. So in UltraSparcIII, even *
35  * the platform supports PAPI_FP_OPS, but UltraSparcIII only has two *
36  * available hardware counters and PAPI_FP_OPS is a derived event in *
37  * this platform, so PAPI_flops returns an error. *
38  ***********************************************************************/
39  if((retval=PAPI_flops(&ireal_time,&iproc_time,&iflpops,&imflops)) < PAPI_OK)
40  {
41  printf("Could not initialise PAPI_flops \n");
42  printf("Your platform may not support floating point operation event.\n");
43  printf("retval: %d\n", retval);
44  exit(1);
45  }
46 
48 
49 
50  if((retval=PAPI_flops( &real_time, &proc_time, &flpops, &mflops))<PAPI_OK)
51  {
52  printf("retval: %d\n", retval);
53  exit(1);
54  }
55 
56 
57  printf("Real_time: %f Proc_time: %f Total flpops: %lld MFLOPS: %f\n",
58  real_time, proc_time,flpops,mflops);
59 
60  exit(0);
61 }
62 
64 {
65  int i;
66  double tmp=1.1;
67 
68  for(i=1; i<2000; i++)
69  {
70  tmp=(tmp+100)/i;
71  }
72  return 0;
73 }
74 
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_flops(float *rtime, float *ptime, long long *flpops, float *mflops)
Definition: papi_hl.c:263
int retval
Definition: zero_fork.c:53
double tmp
Return codes and api definitions.
int your_slow_code()
Definition: PAPI_flops.c:63
main()
Definition: PAPI_flops.c:23
void exit()
int i
Definition: fileop.c:140