-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfourier-bench1-fftw3.cpp
208 lines (187 loc) · 4.27 KB
/
fourier-bench1-fftw3.cpp
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
198
199
200
201
202
203
204
205
206
207
#include "fourier-bench1.h"
#ifdef HAVE_FFTW3_FFT
namespace fftw3 {
#include <fftw3.h>
fftw_plan p;
namespace r2c {
double *in;
complex<double> *out;
struct otest : bench::Test {
explicit otest(int n)
{
bench::init(in, n, out, n/2+1);
p = fftw_plan_dft_r2c_1d(n, reinterpret_cast<double*>(in),
reinterpret_cast<fftw_complex*>(out), FFTW_MEASURE);
bench::header("FFTW3", "r2c", "o", "f", n);
}
~otest()
{
fftw_destroy_plan(p);
bench::free(in, out);
}
void op()
{
fftw_execute(p);
};
string opName() const
{
return "fftw_execute()";
}
};
struct itest : bench::Test {
explicit itest(int n)
{
bench::init(in, 2*(n/2+1));
p = fftw_plan_dft_r2c_1d(n, reinterpret_cast<double*>(in),
reinterpret_cast<fftw_complex*>(in), FFTW_MEASURE);
bench::header("FFTW3", "r2c", "i", "f", n);
}
~itest()
{
fftw_destroy_plan(p);
bench::free(in);
}
void op()
{
fftw_execute(p);
};
string opName() const
{
return "fftw_execute()";
}
};
}
namespace r2r {
double *in, *out;
struct otest : bench::Test {
explicit otest(int n)
{
bench::init(in, n, out, n);
p = fftw_plan_r2r_1d(n, reinterpret_cast<double*>(in),
reinterpret_cast<double*>(out), FFTW_R2HC, FFTW_MEASURE);
bench::header("FFTW3", "r2r", "o", "f", n);
}
~otest()
{
fftw_destroy_plan(p);
bench::free(in, out);
}
void op()
{
fftw_execute(p);
};
string opName() const
{
return "fftw_execute()";
}
};
struct itest : bench::Test {
explicit itest(int n)
{
bench::init(in, n);
p = fftw_plan_r2r_1d(n, reinterpret_cast<double*>(in),
reinterpret_cast<double*>(in), FFTW_R2HC, FFTW_MEASURE);
bench::header("FFTW3","r2r","i","f",n);
}
~itest()
{
fftw_destroy_plan(p);
bench::free(in);
}
void op()
{
fftw_execute(p);
};
string opName() const
{
return "fftw_execute()";
}
};
}
namespace c2c {
complex<double> *in, *out;
struct otest : bench::Test {
explicit otest(int n)
{
bench::init(in, n, out, n);
p = fftw_plan_dft_1d(n, reinterpret_cast<fftw_complex*>(in),
reinterpret_cast<fftw_complex*>(out), FFTW_FORWARD, FFTW_MEASURE);
bench::header("FFTW3", "c2c", "o", "f", n);
}
~otest()
{
fftw_destroy_plan(p);
bench::free(in, out);
}
void op()
{
fftw_execute(p);
};
string opName() const
{
return "fftw_execute()";
}
};
struct itest : bench::Test {
explicit itest(int n)
{
bench::init(in, n);
p = fftw_plan_dft_1d(n, reinterpret_cast<fftw_complex*>(in),
reinterpret_cast<fftw_complex*>(in), FFTW_FORWARD, FFTW_MEASURE);
bench::header("FFTW3", "c2c", "i", "f", n);
}
~itest()
{
fftw_destroy_plan(p);
bench::free(in);
}
void op()
{
fftw_execute(p);
};
string opName() const
{
return "fftw_execute()";
}
};
}
void run(int n, bool verbose)
{
// bench namespace verbose locally scoped
//bench::verbose = true;
fftw_import_system_wisdom();
{
r2c::otest test(n);
bench::bench(test, n, 0.5, verbose);
}
{
r2c::itest test(n);
bench::bench(test, n, 0.5, verbose);
}
{
r2r::otest test(n);
bench::bench(test, n, 0.5, verbose);
}
{
r2r::itest test(n);
bench::bench(test, n, 0.5, verbose);
}
{
c2c::itest test(n);
bench::bench(test, n, 1.0, verbose);
}
{
c2c::itest test(n);
bench::bench(test, n, 1.0, verbose);
}
cout << endl;
}
}
#else
namespace fftw3 {
void run(int n, bool verbose)
{
cout << "FFTW3 port not available." << endl << endl;
}
}
#endif // HAVE_FFTW3_FFT