4
Written by Scott Robert Ladd (scott@coyotegulch.com)
5
No rights reserved. This is public domain software, for use by anyone.
7
A number-crunching benchmark using LUP-decomposition to solve a large
10
The code herein is design for the purpose of testing computational
11
performance; error handling is minimal.
13
In fact, this is a weak implementation of the FFT; unfortunately, all
14
of my really nifty FFTs are in commercial code, and I haven't had time
15
to write a new FFT routine for this benchmark. I may add a Hartley
16
transform to the seat, too.
18
Actual benchmark results can be found at:
19
http://www.coyotegulch.com
21
Please do not use this information or algorithm in any way that might
22
upset the balance of the universe or otherwise cause a disturbance in
23
the space-time continuum.
33
// embedded random number generator; ala Park and Miller
34
static long seed = 1325;
35
static const long IA = 16807;
36
static const long IM = 2147483647;
37
static const double AM = 4.65661287525E-10;
38
static const long IQ = 127773;
39
static const long IR = 2836;
40
static const long MASK = 123459876;
42
static double random_double()
49
seed = IA * (seed - k * IQ) - IR * k;
60
static const int N = 800;
61
static const int NM1 = 799; // N - 1
62
static const int NP1 = 801; // N + 1
64
static int *lup_decompose(double **a)
69
int *perm = (int *) malloc(sizeof(double) * N);
71
for (i = 0; i < N; ++i)
74
for (k = 0; k < NM1; ++k) {
77
for (i = k; i < N; ++i) {
86
// check for invalid a
95
for (i = 0; i < N; ++i) {
101
for (i = k + 1; i < N; ++i) {
104
for (j = k + 1; j < N; ++j)
105
a[i][j] -= a[i][k] * a[k][j];
112
static double *lup_solve(double **a, int *perm, double *b)
117
double *y = (double *) malloc(sizeof(double) * N);
118
double *x = (double *) malloc(sizeof(double) * N);
120
for (i = 0; i < N; ++i) {
125
for (i = 0; i < N; ++i) {
129
for (j = 1; j <= i; ++j) {
130
sum += a[i][j2] * y[j2];
134
y[i] = b[perm[i]] - sum;
143
for (j = i + 1; j < N; ++j)
144
sum += a[i][j] * x[j];
146
x[i] = (y[i] - sum) / u;
159
static double **a, *b, *r;
162
void fft_bench_init(void)
166
// generate test data
167
a = (double **) malloc(sizeof(double *) * N);
169
for (i = 0; i < N; ++i) {
170
a[i] = (double *) malloc(sizeof(double) * N);
172
for (j = 0; j < N; ++j)
173
a[i][j] = random_double();
176
b = (double *) malloc(sizeof(double) * N);
178
for (i = 0; i < N; ++i)
179
b[i] = random_double();
183
void fft_bench_start(void)
185
p = lup_decompose(a);
186
r = lup_solve(a, p, b);
189
void fft_bench_finish(void)
194
for (i = 0; i < N; ++i)