root / synthbench / euroben-ports / base / C / mod2f / .svn / text-base / mod2f.c.svn-base @ 0:839f52ef7657
History | View | Annotate | Download (2.5 kB)
1 |
#include <stdio.h> |
---|---|
2 |
#include <stdlib.h> |
3 |
#include <math.h> |
4 |
|
5 |
double cclock( void ); |
6 |
int check( double a[], double b[], int m, double err ); |
7 |
void cfft4( int, int, double ur[], double ui[], double xr[], double xi[], |
8 |
double wr[], double wi[] ); |
9 |
void gendat( double *a, int ); |
10 |
void nflops( int, int *, int * ); |
11 |
void prthead( void ); |
12 |
void prtspeed( int, double, double, int ); |
13 |
void state( char * ); |
14 |
|
15 |
int main() |
16 |
{ |
17 |
int m, n, nrep; |
18 |
int mflint, mfltrn, ok; |
19 |
int i, j; |
20 |
double *a, *b, *c, *ur, *ui, *wr, *wi; |
21 |
double corr, err, mflops, time; |
22 |
FILE *inl; |
23 |
// ------------------------------------------------------------------------ |
24 |
state( "mod2f" ); |
25 |
prthead(); |
26 |
inl = fopen( "mod2f.in", "r" ); |
27 |
while( ( fscanf( inl, "%d%d\n", &m, &nrep ) != EOF ) ){ |
28 |
n = pow( 2, m ); |
29 |
err = ( 10.0*n*m )* 1.0e-10; // --- Allowed error tolerance. |
30 |
a = calloc( n, sizeof( double ) ); |
31 |
b = calloc( n, sizeof( double ) ); |
32 |
c = calloc( n, sizeof( double ) ); |
33 |
ur = calloc( n, sizeof( double ) ); |
34 |
ui = calloc( n, sizeof( double ) ); |
35 |
wr = calloc( n, sizeof( double ) ); |
36 |
wi = calloc( n, sizeof( double ) ); |
37 |
// ------------------------------------------------------------------------- |
38 |
// --- Generate data. |
39 |
|
40 |
gendat( c, n ); |
41 |
// ------------------------------------------------------------------------- |
42 |
// --- Repeat FFT 'nrep' times for this problem size. |
43 |
|
44 |
time = cclock(); |
45 |
for( i = 0; i < nrep; i++ ) { |
46 |
for( j = 0; j < n; j++ ) { |
47 |
a[j] = c[j]; |
48 |
b[j] = 0.0; |
49 |
} |
50 |
cfft4( 0, m, ur, ui, a, b, wr, wi ); |
51 |
cfft4( 1, m, ur, ui, a, b, wr, wi ); |
52 |
} |
53 |
time = cclock() - time; |
54 |
// ------------------------------------------------------------------------- |
55 |
// --- Check for errors and correct timing for filling of arrays. |
56 |
|
57 |
ok = check( a, b, n, err ); |
58 |
corr = cclock(); |
59 |
for( i = 0; i < nrep; i++ ) { |
60 |
for( j = 0; j < n; j++ ) { |
61 |
a[j] = c[j]; |
62 |
b[j] = 0.0; |
63 |
} |
64 |
} |
65 |
corr = cclock() - corr; |
66 |
time = ( time - corr )/(double)nrep; |
67 |
// ------------------------------------------------------------------------- |
68 |
// --- Calculate Mflop rates. |
69 |
|
70 |
nflops( m, &mflint, &mfltrn ); |
71 |
mflops = 1.0e-6*( mflint + mfltrn )/time; |
72 |
prtspeed( n, time, mflops, ok ); |
73 |
free( wi ); free( wr ); free( ui ); free( ur ); |
74 |
free( c ); free( b ); free( a ); |
75 |
} |
76 |
printf( "-----------------------------------------------\n" ); |
77 |
} |