59 int main(
int argc,
char** argv) {
61 fprintf(stdout,
"Usage: test_s2_semi_fly bw loops [error_file]\n");
65 int bw = atoi(argv[1]);
66 int loops = atoi(argv[2]);
74 double* weights = (
double*)malloc(
sizeof(
double) * 4 * bw);
75 double* rdata = (
double*)malloc(
sizeof(
double) * (size * size));
76 double* idata = (
double*)malloc(
sizeof(
double) * (size * size));
77 double* workspace = (
double*)malloc(
sizeof(
double) * ((10 * (bw * bw)) + (24 * bw)));
80 fftw_plan DCT_plan = fftw_plan_r2r_1d(size, weights, rdata, FFTW_REDFT10, FFTW_ESTIMATE);
81 fftw_plan inv_DCT_plan = fftw_plan_r2r_1d(size, weights, rdata, FFTW_REDFT01, FFTW_ESTIMATE);
86 fftw_iodim dims[rank];
92 fftw_iodim howmany_dims[howmany_rank];
93 howmany_dims[0].n = size;
94 howmany_dims[0].is = size;
95 howmany_dims[0].os = 1;
97 fftw_plan FFT_plan = fftw_plan_guru_split_dft(rank, dims, howmany_rank, howmany_dims, rdata, idata, workspace,
98 workspace + (4 * bw * bw), FFTW_ESTIMATE);
109 howmany_dims[0].n = size;
110 howmany_dims[0].is = 1;
111 howmany_dims[0].os = size;
113 fftw_plan inv_FFT_plan = fftw_plan_guru_split_dft(rank, dims, howmany_rank, howmany_dims, rdata, idata, workspace,
114 workspace + (4 * bw * bw), FFTW_ESTIMATE);
118 double* rcoeffs = (
double*)malloc(
sizeof(
double) * (bw * bw));
119 double* icoeffs = (
double*)malloc(
sizeof(
double) * (bw * bw));
121 double* rresult = (
double*)malloc(
sizeof(
double) * (bw * bw));
122 double* iresult = (
double*)malloc(
sizeof(
double) * (bw * bw));
124 double* relerror = (
double*)malloc(
sizeof(
double) * loops);
125 double* curmax = (
double*)malloc(
sizeof(
double) * loops);
128 int cutoff = (bw / 2) - 10;
131 double fwd_time = 0.0;
132 double inv_time = 0.0;
133 double total_error = 0.0;
134 double total_relerror = 0.0;
136 fprintf(stdout,
"about to enter loop\n\n");
137 for (
int i = 0; i < loops; ++i) {
140 for (
int m = 0; m < bw; ++m)
141 for (
int l = m; l < bw; ++l) {
142 double x = 2.0 * (drand48() - 0.5);
143 double y = 2.0 * (drand48() - 0.5);
150 rcoeffs[index] = pow(-1.0, m) * x;
151 icoeffs[index] = pow(-1.0, m + 1) * y;
155 for (
int m = 0; m < bw; ++m)
160 InvFSTSemiFly(rcoeffs, icoeffs, rdata, idata, bw, workspace, data_format, cutoff, &inv_DCT_plan, &inv_FFT_plan);
162 double duration =
csecond() - time_start;
163 inv_time += duration;
164 fprintf(stdout,
"inv time \t = %.4e\n", duration);
168 FSTSemiFly(rdata, idata, rresult, iresult, bw, workspace, data_format, cutoff, &DCT_plan, &FFT_plan, weights);
170 duration =
csecond() - time_start;
171 fwd_time += duration;
172 fprintf(stdout,
"forward time \t = %.4e\n", duration);
178 for (
int j = 0; j < (bw * bw); ++j) {
179 double rtmp = rresult[j] - rcoeffs[j];
180 double itmp = iresult[j] - icoeffs[j];
181 double origmag = sqrt((rcoeffs[j] * rcoeffs[j]) + (icoeffs[j] * icoeffs[j]));
182 double tmpmag = sqrt((rtmp * rtmp) + (itmp * itmp));
183 relerror[i] = fmax(relerror[i], tmpmag / (origmag + pow(10.0, -50.0)));
184 curmax[i] = fmax(curmax[i], tmpmag);
187 fprintf(stdout,
"r-o error\t = %.12f\n", curmax[i]);
188 fprintf(stdout,
"(r-o)/o error\t = %.12f\n\n", relerror[i]);
190 total_error += curmax[i];
191 total_relerror += relerror[i];
194 double avg_error = total_error / loops;
195 double avg_relerror = total_relerror / loops;
196 double stddev_error = 0.0;
197 double stddev_relerror = 0.0;
199 for (
int i = 0; i < loops; ++i) {
200 stddev_error += pow(avg_error - curmax[i], 2.0);
201 stddev_relerror += pow(avg_relerror - relerror[i], 2.0);
205 stddev_error = sqrt(stddev_error / (loops - 1));
206 stddev_relerror = sqrt(stddev_relerror / (loops - 1));
209 fprintf(stdout,
"Program: test_s2_semi_fly\n");
210 fprintf(stdout,
"Bandwidth = %d\n", bw);
212 const char* timing_object =
"cpu";
214 timing_object =
"wall";
217 double total_time = inv_time + fwd_time;
219 fprintf(stdout,
"Total elapsed %s time:\t\t\t %.4e seconds.\n", timing_object, total_time);
220 fprintf(stdout,
"Average %s time forward per iteration:\t %.4e seconds.\n", timing_object, fwd_time / loops);
221 fprintf(stdout,
"Average %s time inverse per iteration:\t %.4e seconds.\n", timing_object, inv_time / loops);
223 fprintf(stdout,
"Average r-o error:\t\t %.4e\t", total_error / loops);
224 fprintf(stdout,
"std dev: %.4e\n", stddev_error);
225 fprintf(stdout,
"Average (r-o)/o error:\t\t %.4e\t", total_relerror / loops);
226 fprintf(stdout,
"std dev: %.4e\n\n", stddev_relerror);
229 FILE* errorsfp = fopen(argv[3],
"w");
231 for (
int m = 0; m < bw; ++m) {
232 for (
int l = m; l < bw; ++l) {
234 fprintf(errorsfp,
"index = %d\t m = %d\tl = %d\t%.10f %.10f\n", index, m, l,
235 fabs(rcoeffs[index] - rresult[index]), fabs(icoeffs[index] - iresult[index]));
238 fprintf(errorsfp,
"index = %d\t m = %d\tl = %d\t%.10f %.10f\n", index, -m, l,
239 fabs(rcoeffs[index] - rresult[index]), fabs(icoeffs[index] - iresult[index]));
246 fftw_destroy_plan(inv_FFT_plan);
247 fftw_destroy_plan(FFT_plan);
248 fftw_destroy_plan(inv_DCT_plan);
249 fftw_destroy_plan(DCT_plan);