PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
flops.c
Go to the documentation of this file.
1 /*
2  * A simple example for the use of PAPI, the number of flops you should
3  * get is about INDEX^3 on machines that consider add and multiply one flop
4  * such as SGI, and 2*(INDEX^3) that don't consider it 1 flop such as INTEL
5  * -Kevin London
6  */
7 
8 #include "papi_test.h"
9 
10 #define INDEX 1000
11 
12 char format_string[] =
13  { "Real_time: %f Proc_time: %f Total flpins: %lld MFLOPS: %f\n" };
14 extern int TESTS_QUIET; /* Declared in test_utils.c */
15 
16 
17 extern void dummy( void * );
19 int
20 main( int argc, char **argv )
21 {
22  float real_time, proc_time, mflops;
23  long long flpins;
24  int retval;
25  int i, j, k, fip = 0;
26 
27  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
28 
30  if ( retval != PAPI_VER_CURRENT )
31  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
32 
34  fip = 1;
35  else if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK )
36  fip = 2;
37  else {
38  if ( !TESTS_QUIET )
39  printf
40  ( "PAPI_FP_INS and PAPI_FP_OPS are not defined for this platform.\n" );
41  }
42 
43  PAPI_shutdown( );
44 
45  if ( fip > 0 ) {
46  /* Initialize the Matrix arrays */
47  for ( i = 0; i < INDEX; i++ ) {
48  for ( j = 0; j < INDEX; j++) {
49  mresult[j][i] = 0.0;
50  matrixa[j][i] = matrixb[j][i] = ( float ) rand( ) * ( float ) 1.1;
51  }
52  }
53 
54  /* Setup PAPI library and begin collecting data from the counters */
55  if ( fip == 1 ) {
56  if ( ( retval =
57  PAPI_flips( &real_time, &proc_time, &flpins,
58  &mflops ) ) < PAPI_OK )
59  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
60  } else {
61  if ( ( retval =
62  PAPI_flops( &real_time, &proc_time, &flpins,
63  &mflops ) ) < PAPI_OK )
64  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
65  }
66 
67  /* Matrix-Matrix multiply */
68  for ( i = 0; i < INDEX; i++ )
69  for ( j = 0; j < INDEX; j++ )
70  for ( k = 0; k < INDEX; k++ )
71  mresult[i][j] =
72  mresult[i][j] + matrixa[i][k] * matrixb[k][j];
73 
74  /* Collect the data into the variables passed in */
75  if ( fip == 1 ) {
76  if ( ( retval =
77  PAPI_flips( &real_time, &proc_time, &flpins,
78  &mflops ) ) < PAPI_OK )
79  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
80  } else {
81  if ( ( retval =
82  PAPI_flops( &real_time, &proc_time, &flpins,
83  &mflops ) ) < PAPI_OK )
84  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
85  }
86  dummy( ( void * ) mresult );
87 
88  if ( !TESTS_QUIET ) {
89  if ( fip == 1 ) {
90  printf( "Real_time: %f Proc_time: %f Total flpins: ", real_time,
91  proc_time );
92  } else {
93  printf( "Real_time: %f Proc_time: %f Total flpops: ", real_time,
94  proc_time );
95  }
96  printf( LLDFMT, flpins );
97  printf( " MFLOPS: %f\n", mflops );
98  }
99  }
100  test_pass( __FILE__, NULL, 0 );
101  exit( 1 );
102 }
float matrixb[INDEX][INDEX]
Definition: flops.c:18
int PAPI_flops(float *rtime, float *ptime, long long *flpops, float *mflops)
Definition: papi_hl.c:259
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_FP_OPS
Definition: fpapi.h:237
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int dummy
Definition: iozone.c:19741
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int PAPI_flips(float *rtime, float *ptime, long long *flpins, float *mflips)
Definition: papi_hl.c:204
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
void PAPI_shutdown(void)
Definition: papi.c:4344
int k
Definition: iozone.c:19136
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define INDEX
Definition: flops.c:10
float mresult[INDEX][INDEX]
Definition: flops.c:18
#define PAPI_FP_INS
Definition: fpapi.h:187
char format_string[]
Definition: flops.c:12
float matrixa[INDEX][INDEX]
Definition: flops.c:18
int PAPI_query_event(int EventCode)
Definition: papi.c:695
#define LLDFMT
Definition: papi_test.h:118
int rand()
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()