PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
matrix-hl.c File Reference
Include dependency graph for matrix-hl.c:

Go to the source code of this file.

Macros

#define NROWS1   175
 
#define NCOLS1   225
 
#define NROWS2   NCOLS1
 
#define NCOLS2   150
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define NCOLS1   225
#define NCOLS2   150
#define NROWS1   175
#define NROWS2   NCOLS1

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 21 of file matrix-hl.c.

22 {
23 
24 #define NROWS1 175
25 #define NCOLS1 225
26 #define NROWS2 NCOLS1
27 #define NCOLS2 150
28  double p[NROWS1][NCOLS1], q[NROWS2][NCOLS2], r[NROWS1][NCOLS2];
29  int i, j, k, num_events, retval;
30  /* PAPI standardized event to be monitored */
31  int event[2];
32  /* PAPI values of the counters */
33  long long values[2], tmp;
34  int quiet;
35 
36  quiet = tests_quiet( argc, argv );
37 
38  /* Setup default values */
39  num_events = 0;
40 
41  /* See how many hardware events at one time are supported
42  * This also initializes the PAPI library */
43  num_events = PAPI_num_counters( );
44  if ( num_events < 2 ) {
45  if (!quiet) printf( "This example program requries the architecture to "
46  "support 2 simultaneous hardware events...shutting down.\n" );
47  test_skip( __FILE__, __LINE__, "PAPI_num_counters", 1 );
48  }
49 
50  if ( !quiet )
51  printf( "Number of hardware counters supported: %d\n", num_events );
52 
54  event[0] = PAPI_FP_OPS;
55  else if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK )
56  event[0] = PAPI_FP_INS;
57  else
58  event[0] = PAPI_TOT_INS;
59 
60  /* Time used */
61  event[1] = PAPI_TOT_CYC;
62 
63  /* matrix 1: read in the matrix values */
64  for ( i = 0; i < NROWS1; i++ )
65  for ( j = 0; j < NCOLS1; j++ )
66  p[i][j] = i * j * 1.0;
67 
68  for ( i = 0; i < NROWS2; i++ )
69  for ( j = 0; j < NCOLS2; j++ )
70  q[i][j] = i * j * 1.0;
71 
72  for ( i = 0; i < NROWS1; i++ )
73  for ( j = 0; j < NCOLS2; j++ )
74  r[i][j] = i * j * 1.0;
75 
76  /* Set up the counters */
77  num_events = 2;
78  retval = PAPI_start_counters( event, num_events );
79  if ( retval != PAPI_OK )
80  test_fail( __FILE__, __LINE__, "PAPI_start_counters", retval );
81 
82  /* Clear the counter values */
83  retval = PAPI_read_counters( values, num_events );
84  if ( retval != PAPI_OK )
85  test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
86 
87  /* Compute the matrix-matrix multiplication */
88  for ( i = 0; i < NROWS1; i++ )
89  for ( j = 0; j < NCOLS2; j++ )
90  for ( k = 0; k < NCOLS1; k++ )
91  r[i][j] = r[i][j] + p[i][k] * q[k][j];
92 
93  /* Stop the counters and put the results in the array values */
94  retval = PAPI_stop_counters( values, num_events );
95  if ( retval != PAPI_OK )
96  test_fail( __FILE__, __LINE__, "PAPI_stop_counters", retval );
97 
98  /* Make sure the compiler does not optimize away the multiplication
99  * with dummy(r);
100  */
101  dummy( r );
102 
103  if ( !quiet ) {
104  if ( event[0] == PAPI_TOT_INS ) {
105  printf( TAB1, "TOT Instructions:", values[0] );
106  } else {
107  printf( TAB1, "FP Instructions:", values[0] );
108  }
109  printf( TAB1, "Cycles:", values[1] );
110  }
111 
112  /*
113  * Intel Core overreports flops by 50% when using -O
114  * Use -O2 or -O3 to produce the expected # of flops
115  */
116 
117  if ( event[0] == PAPI_FP_INS ) {
118  /* Compare measured FLOPS to expected value */
119  tmp =
120  2 * ( long long ) ( NROWS1 ) * ( long long ) ( NCOLS2 ) *
121  ( long long ) ( NCOLS1 );
122  if ( abs( ( int ) values[0] - ( int ) tmp ) > ( double ) tmp * 0.05 ) {
123  /* Maybe we are counting FMAs? */
124  tmp = tmp / 2;
125  if ( abs( ( int ) values[0] - ( int ) tmp ) >
126  ( double ) tmp * 0.05 ) {
127  printf( "\n" TAB1, "Expected operation count: ", 2 * tmp );
128  printf( TAB1, "Or possibly (using FMA): ", tmp );
129  printf( TAB1, "Instead I got: ", values[0] );
130  test_fail( __FILE__, __LINE__,
131  "Unexpected FLOP count (check vector operations)",
132  1 );
133  }
134  }
135  }
136  test_pass( __FILE__ );
137 
138  return 0;
139 
140 }
void test_pass(const char *filename)
Definition: test_utils.c:432
#define NROWS1
#define PAPI_FP_OPS
static int num_events
#define TAB1
Definition: papi_test.h:88
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:497
static double
Definition: fileop.c:1281
int int argc
Definition: iozone.c:1609
int dummy
Definition: iozone.c:19741
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
#define NROWS2
int i
Definition: fileop.c:140
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
int k
Definition: iozone.c:19136
#define NCOLS2
long long
Definition: iozone.c:19827
#define NCOLS1
int PAPI_query_event(int EventCode)
Definition: papi.c:684
printf("\tTry: -i 0 -i 1 \n\n")
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
int PAPI_read_counters(long long *values, int array_len)
Definition: papi_hl.c:706
int
Definition: iozone.c:18528
int PAPI_num_counters(void)
Definition: papi_hl.c:537
int PAPI_start_counters(int *events, int array_len)
Definition: papi_hl.c:593
long j
Definition: iozone.c:19135
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
#define PAPI_FP_INS

Here is the call graph for this function: