PAPI 7.1.0.0
Loading...
Searching...
No Matches
PAPI_flops.c
Go to the documentation of this file.
1/*****************************************************************************
2 * This example demonstrates the usage of the function PAPI_flops_rate *
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_rate you need to have floating point *
6 * operations events supported by the platform. *
7 *****************************************************************************/
8
9/*****************************************************************************
10 * The first call to PAPI_flops_rate initializes the PAPI library, set up *
11 * the counters to monitor the floating point operations event, and start *
12 * the counters. Subsequent calls will read the counters and return *
13 * real time, process time, floating point operations, and the Mflops/s rate *
14 * since the latest call to PAPI_flops_rate. *
15 *****************************************************************************/
16
17
18#include <stdio.h>
19#include <stdlib.h>
20#include "papi.h"
21
22int your_slow_code();
23
24int main()
25{
26 float real_time, proc_time,mflops;
27 long long flpops;
28 float ireal_time, iproc_time, imflops;
29 long long iflpops;
30 int retval;
31
32 /***********************************************************************
33 * If PAPI_FP_OPS is a derived event in your platform, then your *
34 * platform must have at least three counters to support *
35 * PAPI_flops_rate, because PAPI needs one counter for cycles. So in *
36 * UltraSparcIII, even though the platform supports PAPI_FP_OPS, *
37 * UltraSparcIII only has two available hardware counters, and *
38 * PAPI_FP_OPS is a derived event that requires both of them, so *
39 * PAPI_flops_rate returns an error. *
40 ***********************************************************************/
41 if((retval=PAPI_flops_rate(PAPI_FP_OPS,&ireal_time,&iproc_time,&iflpops,&imflops)) < PAPI_OK)
42 {
43 printf("Could not initialise PAPI_flops \n");
44 printf("Your platform may not support floating point operation event.\n");
45 printf("retval: %d\n", retval);
46 exit(1);
47 }
48
50
51
52 if((retval=PAPI_flops_rate(PAPI_FP_OPS,&real_time, &proc_time, &flpops, &mflops))<PAPI_OK)
53 {
54 printf("retval: %d\n", retval);
55 exit(1);
56 }
57
58
59 printf("Real_time: %f Proc_time: %f flpops: %lld MFLOPS: %f\n",
60 real_time, proc_time,flpops,mflops);
61
62 exit(0);
63}
64
66{
67 int i;
68 double tmp=1.1;
69
70 for(i=1; i<2000; i++)
71 {
72 tmp=(tmp+100)/i;
73 }
74 return 0;
75}
76
int your_slow_code()
Definition: PAPI_flops.c:65
int main()
Definition: PAPI_flops.c:24
double tmp
int i
Simplified call to get Mflops/s (floating point operation rate), real and processor time.
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_FP_OPS
Definition: f90papi.h:319
Return codes and api definitions.
int retval
Definition: zero_fork.c:53