PAPI 7.1.0.0
Loading...
Searching...
No Matches
PAPI_flips.c
Go to the documentation of this file.
1/*****************************************************************************
2 * This example demonstrates the usage of the function PAPI_flips_rate which *
3 * measures the number of floating point instructions executed and the *
4 * MegaFlip rate(defined as the number of floating point instructions per *
5 * microsecond). To use PAPI_flips_rate you need to have floating point *
6 * instructions events supported by the platform. *
7 *****************************************************************************/
8
9/*****************************************************************************
10 * The first call to PAPI_flips_rate initializes the PAPI library, set up *
11 * the counters to monitor the floating point instructions event, and start *
12 * the counters. Subsequent calls will read the counters and return *
13 * real time, process time, floating point instructions, and the Mflips/s *
14 * rate since the latest call to PAPI_flips_rate. *
15 *****************************************************************************/
16
17
18
19#include <stdio.h>
20#include <stdlib.h>
21#include "papi.h"
22
23int your_slow_code();
24
25int main()
26{
27 float real_time, proc_time,mflips;
28 long long flpins;
29 float ireal_time, iproc_time, imflips;
30 long long iflpins;
31 int retval;
32
33 /***********************************************************************
34 * if PAPI_FP_INS is a derived event in your platform, then your *
35 * platform must have at least three counters to support PAPI_flips, *
36 * because PAPI needs one counter to cycles. So in UltraSparcIII, even *
37 * the platform supports PAPI_FP_INS, but UltraSparcIII only have two *
38 * available hardware counters and PAPI_FP_INS is a derived event in *
39 * this platform, so PAPI_flops returns an error. *
40 ***********************************************************************/
41
42 if((retval=PAPI_flips_rate(PAPI_FP_INS,&ireal_time,&iproc_time,&iflpins,&imflips)) < PAPI_OK)
43 {
44 printf("Could not initialise PAPI_flips \n");
45 printf("Your platform may not support floating point instruction event.\n"); printf("retval: %d\n", retval);
46 exit(1);
47 }
48
50
51
52 if((retval=PAPI_flips_rate(PAPI_FP_INS,&real_time, &proc_time, &flpins, &mflips))<PAPI_OK)
53 {
54 printf("retval: %d\n", retval);
55 exit(1);
56 }
57
58
59 printf("Real_time: %f Proc_time: %f flpins: %lld MFLIPS: %f\n",
60 real_time, proc_time,flpins,mflips);
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_flips.c:65
int main()
Definition: PAPI_flips.c:25
double tmp
int i
Simplified call to get Mflips/s (floating point instruction rate), real and processor time.
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_FP_INS
Definition: f90papi.h:366
Return codes and api definitions.
int retval
Definition: zero_fork.c:53