-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmfft1r.cc
157 lines (133 loc) · 3.02 KB
/
mfft1r.cc
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
#include "Complex.h"
#include "Array.h"
#include "fftw++.h"
#include "utils.h"
#include "timing.h"
using namespace std;
using namespace utils;
using namespace Array;
using namespace fftwpp;
inline void init(array2<double>& f, size_t mx, size_t my)
{
for(size_t i=0; i < mx; ++i)
for(size_t j=0; j < my; j++)
f[i][j] = 10 * i + j;
}
size_t outlimit=100;
int main(int argc, char *argv[])
{
fftw::maxthreads=get_max_threads();
// Number of iterations.
size_t N0=10000000;
size_t N=0;
size_t mx=4;
size_t my=4;
size_t stats=0; // Type of statistics used in timing test.
bool Nset = false;
#ifndef __SSE2__
fftw::effort |= FFTW_NO_SIMD;
#endif
#ifdef __GNUC__
optind=0;
#endif
for (;;) {
int c = getopt(argc,argv,"hN:m:x:y:n:T:S:");
if (c == -1) break;
switch (c) {
case 0:
break;
case 'N':
Nset = true;
N=atoi(optarg);
break;
case 'm':
mx=my=atoi(optarg);
break;
case 'x':
mx=atoi(optarg);
break;
case 'y':
my=atoi(optarg);
break;
case 'n':
N0=atoi(optarg);
break;
case 'T':
fftw::maxthreads=max(atoi(optarg),1);
break;
case 'S':
stats=atoi(optarg);
break;
case 'h':
default:
usageCommon(2);
exit(0);
}
}
if(my == 0) my=mx;
cout << "mx=" << mx << ", my=" << my << endl;
size_t np=mx/2+1;
cout << "np=" << np << endl;
size_t M=my;
if(!Nset) {
N=N0/mx/my;
if(N < 10) N=10;
}
cout << "N=" << N << endl;
size_t align=ALIGNMENT;
array2<double> f(mx,my,align);
array2<Complex> g(np,my,align);
size_t rstride=1;
size_t cstride=1;
size_t rdist=mx;
size_t cdist=np;
mrcfft1d Forward(mx, // length of transform
M, // number of transforms
rstride,
cstride,
rdist,
cdist,
f, // input array
g); // output array
mcrfft1d Backward(mx, // length of transform
M, // number of transforms
cstride,
rstride,
cdist,
rdist,
g, // input array
f); // output array
cout << "\nInput:" << endl;
init(f,mx,my);
if(mx*my < outlimit)
cout << f << endl;
else
cout << f[0][0] << endl;
cout << "\nOutput:" << endl;
Forward.fft(f,g);
if(mx*my < outlimit)
cout << g << endl;
else
cout << g[0][0] << endl;
cout << "\nBack to input:" << endl;
Backward.fftNormalized(g,f);
if(mx*my < outlimit)
cout << f << endl;
else
cout << f[0][0] << endl;
cout << endl;
if(N > 0) {
double *T=new double[N];
for(size_t i=0; i < N; ++i) {
init(f,mx,my);
double t0=nanoseconds();
Forward.fft(f,g);
Backward.fft(g,f);
T[i]=0.5*nanoseconds()-t0;
Backward.Normalize(f);
}
timings("mfft1r, in-place",mx,T,N,stats);
delete [] T;
}
return 0;
}