File: flops_testcode.c

package info (click to toggle)
papi 5.7.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (197 lines) | stat: -rw-r--r-- 4,059 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* This includes various workloads that had been scattered all over */
/* the various ctests.  The goal is to have them in one place, and */
/* share them, as well as maybe have only one file that has to be */
/* compiled with reduced optimizations */

#include <stdio.h>
#include <stdlib.h>

#include "testcode.h"

#define ROWS	1000
#define COLUMNS	1000

static float float_matrixa[ROWS][COLUMNS],
		float_matrixb[ROWS][COLUMNS],
		float_mresult[ROWS][COLUMNS];

static double double_matrixa[ROWS][COLUMNS],
		double_matrixb[ROWS][COLUMNS],
		double_mresult[ROWS][COLUMNS];


int flops_float_init_matrix(void) {

	int i,j;

	/* Initialize the Matrix arrays */
	/* Non-optimail row major.  Intentional? */
	for ( i = 0; i < ROWS; i++ ) {
		for ( j = 0; j < COLUMNS; j++) {
			float_mresult[j][i] = 0.0;
			float_matrixa[j][i] = ( float ) rand() * ( float ) 1.1;
			float_matrixb[j][i] = ( float ) rand() * ( float ) 1.1;
		}
	}

#if defined(__powerpc__)
	/* Has fused multiply-add */
	return ROWS*ROWS*ROWS;
#else
	return ROWS*ROWS*ROWS*2;
#endif

}

float flops_float_matrix_matrix_multiply(void) {

	int i,j,k;

	/* Matrix-Matrix multiply */
	for ( i = 0; i < ROWS; i++ ) {
		for ( j = 0; j < COLUMNS; j++ ) {
			for ( k = 0; k < COLUMNS; k++ ) {
				float_mresult[i][j] += float_matrixa[i][k] * float_matrixb[k][j];
			}
		}
	}

	return float_mresult[10][10];
}

float flops_float_swapped_matrix_matrix_multiply(void) {

	int i, j, k;

	/* Matrix-Matrix multiply */
	/* With inner loops swapped */

	for (i = 0; i < ROWS; i++) {
		for (k = 0; k < COLUMNS; k++) {
			for (j = 0; j < COLUMNS; j++) {
				float_mresult[i][j] += float_matrixa[i][k] * float_matrixb[k][j];
			}
		}
	}
	return float_mresult[10][10];
}



int flops_double_init_matrix(void) {

	int i,j;

	/* Initialize the Matrix arrays */
	/* Non-optimail row major.  Intentional? */
	for ( i = 0; i < ROWS; i++ ) {
		for ( j = 0; j < COLUMNS; j++) {
			double_mresult[j][i] = 0.0;
			double_matrixa[j][i] = ( double ) rand() * ( double ) 1.1;
			double_matrixb[j][i] = ( double ) rand() * ( double ) 1.1;
		}
	}

#if defined(__powerpc__)
		/* has fused multiply-add */
		return ROWS*ROWS*ROWS;
#else
	return ROWS*ROWS*ROWS*2;
#endif

}

double flops_double_matrix_matrix_multiply(void) {

	int i,j,k;

	/* Matrix-Matrix multiply */
	for ( i = 0; i < ROWS; i++ ) {
		for ( j = 0; j < COLUMNS; j++ ) {
			for ( k = 0; k < COLUMNS; k++ ) {
				double_mresult[i][j] += double_matrixa[i][k] * double_matrixb[k][j];
			}
		}
	}

	return double_mresult[10][10];
}

double flops_double_swapped_matrix_matrix_multiply(void) {

	int i, j, k;

	/* Matrix-Matrix multiply */
	/* With inner loops swapped */

	for (i = 0; i < ROWS; i++) {
		for (k = 0; k < COLUMNS; k++) {
			for (j = 0; j < COLUMNS; j++) {
				double_mresult[i][j] += double_matrixa[i][k] * double_matrixb[k][j];
			}
		}
	}
	return double_mresult[10][10];
}


/* This was originally called "dummy3" in the various sdsc tests */
/* Does a lot of floating point ops near 1.0 */
/* In theory returns a value roughly equal to the number of flops */
double
do_flops3( double x, int iters, int quiet )
{
	int i;
	double w, y, z, a, b, c, d, e, f, g, h;
	double result;
	double one;
	one = 1.0;
	w = x;
	y = x;
	z = x;
	a = x;
	b = x;
	c = x;
	d = x;
	e = x;
	f = x;
	g = x;
	h = x;
	for ( i = 1; i <= iters; i++ ) {
		w = w * 1.000000000001 + one;
		y = y * 1.000000000002 + one;
		z = z * 1.000000000003 + one;
		a = a * 1.000000000004 + one;
		b = b * 1.000000000005 + one;
		c = c * 0.999999999999 + one;
		d = d * 0.999999999998 + one;
		e = e * 0.999999999997 + one;
		f = f * 0.999999999996 + one;
		g = h * 0.999999999995 + one;
		h = h * 1.000000000006 + one;
	}
	result = 2.0 * ( a + b + c + d + e + f + w + x + y + z + g + h );

	if (!quiet) printf("Result = %lf\n", result);

	return result;
}


volatile double a = 0.5, b = 2.2;

double
do_flops( int n, int quiet )
{
        int i;
        double c = 0.11;

        for ( i = 0; i < n; i++ ) {
                c += a * b;
        }

	if (!quiet) printf("%lf\n",c);

	return c;
}