PAPI  5.7.0.0
flops_testcode.c
Go to the documentation of this file.
1 /* This includes various workloads that had been scattered all over */
2 /* the various ctests. The goal is to have them in one place, and */
3 /* share them, as well as maybe have only one file that has to be */
4 /* compiled with reduced optimizations */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "testcode.h"
10 
11 #define ROWS 1000
12 #define COLUMNS 1000
13 
14 static float float_matrixa[ROWS][COLUMNS],
17 
18 static double double_matrixa[ROWS][COLUMNS],
21 
22 
24 
25  int i,j;
26 
27  /* Initialize the Matrix arrays */
28  /* Non-optimail row major. Intentional? */
29  for ( i = 0; i < ROWS; i++ ) {
30  for ( j = 0; j < COLUMNS; j++) {
31  float_mresult[j][i] = 0.0;
32  float_matrixa[j][i] = ( float ) rand() * ( float ) 1.1;
33  float_matrixb[j][i] = ( float ) rand() * ( float ) 1.1;
34  }
35  }
36 
37 #if defined(__powerpc__)
38  /* Has fused multiply-add */
39  return ROWS*ROWS*ROWS;
40 #else
41  return ROWS*ROWS*ROWS*2;
42 #endif
43 
44 }
45 
47 
48  int i,j,k;
49 
50  /* Matrix-Matrix multiply */
51  for ( i = 0; i < ROWS; i++ ) {
52  for ( j = 0; j < COLUMNS; j++ ) {
53  for ( k = 0; k < COLUMNS; k++ ) {
54  float_mresult[i][j] += float_matrixa[i][k] * float_matrixb[k][j];
55  }
56  }
57  }
58 
59  return float_mresult[10][10];
60 }
61 
63 
64  int i, j, k;
65 
66  /* Matrix-Matrix multiply */
67  /* With inner loops swapped */
68 
69  for (i = 0; i < ROWS; i++) {
70  for (k = 0; k < COLUMNS; k++) {
71  for (j = 0; j < COLUMNS; j++) {
72  float_mresult[i][j] += float_matrixa[i][k] * float_matrixb[k][j];
73  }
74  }
75  }
76  return float_mresult[10][10];
77 }
78 
79 
80 
82 
83  int i,j;
84 
85  /* Initialize the Matrix arrays */
86  /* Non-optimail row major. Intentional? */
87  for ( i = 0; i < ROWS; i++ ) {
88  for ( j = 0; j < COLUMNS; j++) {
89  double_mresult[j][i] = 0.0;
90  double_matrixa[j][i] = ( double ) rand() * ( double ) 1.1;
91  double_matrixb[j][i] = ( double ) rand() * ( double ) 1.1;
92  }
93  }
94 
95 #if defined(__powerpc__)
96  /* has fused multiply-add */
97  return ROWS*ROWS*ROWS;
98 #else
99  return ROWS*ROWS*ROWS*2;
100 #endif
101 
102 }
103 
105 
106  int i,j,k;
107 
108  /* Matrix-Matrix multiply */
109  for ( i = 0; i < ROWS; i++ ) {
110  for ( j = 0; j < COLUMNS; j++ ) {
111  for ( k = 0; k < COLUMNS; k++ ) {
112  double_mresult[i][j] += double_matrixa[i][k] * double_matrixb[k][j];
113  }
114  }
115  }
116 
117  return double_mresult[10][10];
118 }
119 
121 
122  int i, j, k;
123 
124  /* Matrix-Matrix multiply */
125  /* With inner loops swapped */
126 
127  for (i = 0; i < ROWS; i++) {
128  for (k = 0; k < COLUMNS; k++) {
129  for (j = 0; j < COLUMNS; j++) {
130  double_mresult[i][j] += double_matrixa[i][k] * double_matrixb[k][j];
131  }
132  }
133  }
134  return double_mresult[10][10];
135 }
136 
137 
138 /* This was originally called "dummy3" in the various sdsc tests */
139 /* Does a lot of floating point ops near 1.0 */
140 /* In theory returns a value roughly equal to the number of flops */
141 double
142 do_flops3( double x, int iters, int quiet )
143 {
144  int i;
145  double w, y, z, a, b, c, d, e, f, g, h;
146  double result;
147  double one;
148  one = 1.0;
149  w = x;
150  y = x;
151  z = x;
152  a = x;
153  b = x;
154  c = x;
155  d = x;
156  e = x;
157  f = x;
158  g = x;
159  h = x;
160  for ( i = 1; i <= iters; i++ ) {
161  w = w * 1.000000000001 + one;
162  y = y * 1.000000000002 + one;
163  z = z * 1.000000000003 + one;
164  a = a * 1.000000000004 + one;
165  b = b * 1.000000000005 + one;
166  c = c * 0.999999999999 + one;
167  d = d * 0.999999999998 + one;
168  e = e * 0.999999999997 + one;
169  f = f * 0.999999999996 + one;
170  g = h * 0.999999999995 + one;
171  h = h * 1.000000000006 + one;
172  }
173  result = 2.0 * ( a + b + c + d + e + f + w + x + y + z + g + h );
174 
175  if (!quiet) printf("Result = %lf\n", result);
176 
177  return result;
178 }
179 
180 
181 volatile double a = 0.5, b = 2.2;
182 
183 double
184 do_flops( int n, int quiet )
185 {
186  int i;
187  double c = 0.11;
188 
189  for ( i = 0; i < n; i++ ) {
190  c += a * b;
191  }
192 
193  if (!quiet) printf("%lf\n",c);
194 
195  return c;
196 }
197 
volatile double b
double f(double a)
Definition: cpi.c:23
#define COLUMNS
double flops_double_matrix_matrix_multiply(void)
#define ROWS
double do_flops3(double x, int iters, int quiet)
static double double_mresult[ROWS][COLUMNS]
double c
Definition: multiplex.c:22
double flops_double_swapped_matrix_matrix_multiply(void)
float flops_float_swapped_matrix_matrix_multiply(void)
static double double_matrixb[ROWS][COLUMNS]
static double double_matrixa[ROWS][COLUMNS]
int one
int quiet
Definition: rapl_overflow.c:18
int flops_float_init_matrix(void)
volatile double a
double do_flops(int n, int quiet)
static float float_matrixb[ROWS][COLUMNS]
int x
Definition: fileop.c:78
int rand()
static float float_mresult[ROWS][COLUMNS]
float flops_float_matrix_matrix_multiply(void)
static float float_matrixa[ROWS][COLUMNS]
int flops_double_init_matrix(void)
int i
Definition: fileop.c:140
long long y
Definition: iozone.c:1335