49 int main(
int argc,
char **argv)
59 C (*kernel)(R, int,
const R *);
71 printf(
"\nfastsum_test d N M n m p kernel c eps_I eps_B\n\n");
72 printf(
" d dimension \n");
73 printf(
" N number of source nodes \n");
74 printf(
" M number of target nodes \n");
75 printf(
" n expansion degree \n");
76 printf(
" m cut-off parameter \n");
77 printf(
" p degree of smoothness \n");
78 printf(
" kernel kernel function (e.g., gaussian)\n");
79 printf(
" c kernel parameter \n");
80 printf(
" eps_I inner boundary \n");
81 printf(
" eps_B outer boundary \n\n");
88 c = K(1.0) / POW((R)(N), K(1.0) / ((R)(d)));
94 c = (R)(atof(argv[8]));
95 eps_I = (R)(atof(argv[9]));
96 eps_B = (R)(atof(argv[10]));
97 if (strcmp(s,
"gaussian") == 0)
99 else if (strcmp(s,
"multiquadric") == 0)
100 kernel = multiquadric;
101 else if (strcmp(s,
"inverse_multiquadric") == 0)
102 kernel = inverse_multiquadric;
103 else if (strcmp(s,
"logarithm") == 0)
105 else if (strcmp(s,
"thinplate_spline") == 0)
106 kernel = thinplate_spline;
107 else if (strcmp(s,
"one_over_square") == 0)
108 kernel = one_over_square;
109 else if (strcmp(s,
"one_over_modulus") == 0)
110 kernel = one_over_modulus;
111 else if (strcmp(s,
"one_over_x") == 0)
113 else if (strcmp(s,
"inverse_multiquadric3") == 0)
114 kernel = inverse_multiquadric3;
115 else if (strcmp(s,
"sinc_kernel") == 0)
116 kernel = sinc_kernel;
117 else if (strcmp(s,
"cosc") == 0)
119 else if (strcmp(s,
"cot") == 0)
124 kernel = multiquadric;
128 "d=%d, N=%d, M=%d, n=%d, m=%d, p=%d, kernel=%s, c=%" __FGS__
", eps_I=%" __FGS__
", eps_B=%" __FGS__
" \n",
129 d, N, M, n, m, p, s, c, eps_I, eps_B);
131 printf(
"nearfield correction using piecewise cubic Lagrange interpolation\n");
132 #elif defined(NF_QUADR)
133 printf(
"nearfield correction using piecewise quadratic Lagrange interpolation\n");
134 #elif defined(NF_LIN)
135 printf(
"nearfield correction using piecewise linear Lagrange interpolation\n");
143 printf(
"nthreads=%d\n", omp_get_max_threads());
147 FFTW(init_threads)();
151 fastsum_init_guru(&my_fastsum_plan, d, N, M, kernel, &c, 0, n, m, p, eps_I,
155 if (my_fastsum_plan.
flags & NEARFIELD_BOXES)
157 "determination of nearfield candidates based on partitioning into boxes\n");
159 printf(
"determination of nearfield candidates based on search tree\n");
165 R r_max = K(0.25) - my_fastsum_plan.
eps_B / K(2.0);
168 for (j = 0; j < d; j++)
169 my_fastsum_plan.
x[k * d + j] = K(2.0) * r_max * NFFT(drand48)() - r_max;
171 for (j = 0; j < d; j++)
172 r2 += my_fastsum_plan.
x[k * d + j] * my_fastsum_plan.
x[k * d + j];
174 if (r2 >= r_max * r_max)
180 for (k = 0; k < N; k++)
195 my_fastsum_plan.
alpha[k] = NFFT(drand48)() + II * NFFT(drand48)();
202 R r_max = K(0.25) - my_fastsum_plan.
eps_B / K(2.0);
205 for (j = 0; j < d; j++)
206 my_fastsum_plan.
y[k * d + j] = K(2.0) * r_max * NFFT(drand48)() - r_max;
208 for (j = 0; j < d; j++)
209 r2 += my_fastsum_plan.
y[k * d + j] * my_fastsum_plan.
y[k * d + j];
211 if (r2 >= r_max * r_max)
233 printf(
"direct computation: ");
238 time = NFFT(elapsed_seconds)(t1, t0);
239 printf(__FI__
"sec\n", time);
242 direct = (C *) NFFT(malloc)((size_t)(my_fastsum_plan.
M_total) * (
sizeof(C)));
243 for (j = 0; j < my_fastsum_plan.
M_total; j++)
244 direct[j] = my_fastsum_plan.
f[j];
247 printf(
"pre-computation: ");
252 time = NFFT(elapsed_seconds)(t1, t0);
253 printf(__FI__
"sec\n", time);
256 printf(
"fast computation: ");
261 time = NFFT(elapsed_seconds)(t1, t0);
262 printf(__FI__
"sec\n", time);
266 for (j = 0; j < my_fastsum_plan.
M_total; j++)
268 if (CABS(direct[j] - my_fastsum_plan.
f[j]) / CABS(direct[j]) > error)
269 error = CABS(direct[j] - my_fastsum_plan.
f[j]) / CABS(direct[j]);
271 printf(
"max relative error: %" __FES__
"\n", error);