NFFT Logo 3.2.3
flags.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: flags.c 3896 2012-10-10 12:19:26Z tovo $ */
20 
29 #include "config.h"
30 
31 #include <stdio.h>
32 #include <math.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #ifdef HAVE_COMPLEX_H
36 #include <complex.h>
37 #endif
38 
39 #include "nfft3util.h"
40 #include "nfft3.h"
41 #include "infft.h"
42 
43 #ifdef GAUSSIAN
44  unsigned test_fg=1;
45 #else
46  unsigned test_fg=0;
47 #endif
48 
49 #ifdef MEASURE_TIME_FFTW
50  unsigned test_fftw=1;
51 #else
52  unsigned test_fftw=0;
53 #endif
54 
55 #ifdef MEASURE_TIME
56  unsigned test=1;
57 #else
58  unsigned test=0;
59 #endif
60 
61 static void flags_cp(nfft_plan *dst, nfft_plan *src)
62 {
63  dst->x=src->x;
64  dst->f_hat=src->f_hat;
65  dst->f=src->f;
66  dst->g1=src->g1;
67  dst->g2=src->g2;
68  dst->my_fftw_plan1=src->my_fftw_plan1;
69  dst->my_fftw_plan2=src->my_fftw_plan2;
70 }
71 
72 static void time_accuracy(int d, int N, int M, int n, int m, unsigned test_ndft,
73  unsigned test_pre_full_psi)
74 {
75  int r, NN[d], nn[d];
76  double t_ndft, t, e;
77  double _Complex *swapndft = NULL;
78  ticks t0, t1;
79 
80  nfft_plan p;
81  nfft_plan p_pre_phi_hut;
82  nfft_plan p_fg_psi;
83  nfft_plan p_pre_lin_psi;
84  nfft_plan p_pre_fg_psi;
85  nfft_plan p_pre_psi;
86  nfft_plan p_pre_full_psi;
87 
88  printf("%d\t%d\t", d, N);
89 
90  for(r=0; r<d; r++)
91  {
92  NN[r]=N;
93  nn[r]=n;
94  }
95 
97  if(test_ndft)
98  swapndft=(double _Complex*)nfft_malloc(M*sizeof(double _Complex));
99 
100  nfft_init_guru(&p, d, NN, M, nn, m,
101  MALLOC_X| MALLOC_F_HAT| MALLOC_F|
102  FFTW_INIT| FFT_OUT_OF_PLACE,
103  FFTW_MEASURE| FFTW_DESTROY_INPUT);
104 
107 
108  nfft_init_guru(&p_pre_phi_hut, d, NN, M, nn, m, PRE_PHI_HUT,0);
109  flags_cp(&p_pre_phi_hut, &p);
110  nfft_precompute_one_psi(&p_pre_phi_hut);
111 
112  if(test_fg)
113  {
114  nfft_init_guru(&p_fg_psi, d, NN, M, nn, m, FG_PSI,0);
115  flags_cp(&p_fg_psi, &p);
116  nfft_precompute_one_psi(&p_fg_psi);
117  }
118 
119  nfft_init_guru(&p_pre_lin_psi, d, NN, M, nn, m, PRE_LIN_PSI,0);
120  flags_cp(&p_pre_lin_psi, &p);
121  nfft_precompute_one_psi(&p_pre_lin_psi);
122 
123  if(test_fg)
124  {
125  nfft_init_guru(&p_pre_fg_psi, d, NN, M, nn, m, PRE_FG_PSI,0);
126  flags_cp(&p_pre_fg_psi, &p);
127  nfft_precompute_one_psi(&p_pre_fg_psi);
128  }
129 
130  nfft_init_guru(&p_pre_psi, d, NN, M, nn, m, PRE_PSI,0);
131  flags_cp(&p_pre_psi, &p);
132  nfft_precompute_one_psi(&p_pre_psi);
133 
134  if(test_pre_full_psi)
135  {
136  nfft_init_guru(&p_pre_full_psi, d, NN, M, nn, m, PRE_FULL_PSI,0);
137  flags_cp(&p_pre_full_psi, &p);
138  nfft_precompute_one_psi(&p_pre_full_psi);
139  }
140 
143 
145  if(test_ndft)
146  {
147  NFFT_SWAP_complex(p.f,swapndft);
148 
149  t_ndft=0;
150  r=0;
151  while(t_ndft<0.01)
152  {
153  r++;
154  t0 = getticks();
155  nfft_trafo_direct(&p);
156  t1 = getticks();
157  t = nfft_elapsed_seconds(t1,t0);
158  t_ndft+=t;
159  }
160  t_ndft/=r;
161 
162  NFFT_SWAP_complex(p.f,swapndft);
163  }
164  else
165  t_ndft=nan("");
166 
168  nfft_trafo(&p);
169  nfft_trafo(&p_pre_phi_hut);
170  if(test_fg)
171  nfft_trafo(&p_fg_psi);
172  else
173  p_fg_psi.MEASURE_TIME_t[2]=nan("");
174  nfft_trafo(&p_pre_lin_psi);
175  if(test_fg)
176  nfft_trafo(&p_pre_fg_psi);
177  else
178  p_pre_fg_psi.MEASURE_TIME_t[2]=nan("");
179  nfft_trafo(&p_pre_psi);
180  if(test_pre_full_psi)
181  nfft_trafo(&p_pre_full_psi);
182  else
183  p_pre_full_psi.MEASURE_TIME_t[2]=nan("");
184 
185  if(test_fftw==0)
186  p.MEASURE_TIME_t[1]=nan("");
187 
188  if(test_ndft)
189  e=X(error_l_2_complex)(swapndft, p.f, p.M_total);
190  else
191  e=nan("");
192 
193  printf("%.2e\t%d\t%.2e\t%.2e\t%.2e\t%.2e\t%.2e\t%.2e\t%.2e\t%.2e\t%.2e\t%.2e\n",
194  t_ndft,
195  m,
196  e,
197  p.MEASURE_TIME_t[0],
198  p_pre_phi_hut.MEASURE_TIME_t[0],
199 
200  p.MEASURE_TIME_t[1],
201 
202  p.MEASURE_TIME_t[2],
203  p_fg_psi.MEASURE_TIME_t[2],
204  p_pre_lin_psi.MEASURE_TIME_t[2],
205  p_pre_fg_psi.MEASURE_TIME_t[2],
206  p_pre_psi.MEASURE_TIME_t[2],
207  p_pre_full_psi.MEASURE_TIME_t[2]);
208 
209  fflush(stdout);
210 
212  if(test_pre_full_psi)
213  nfft_finalize(&p_pre_full_psi);
214  nfft_finalize(&p_pre_psi);
215  if(test_fg)
216  nfft_finalize(&p_pre_fg_psi);
217  nfft_finalize(&p_pre_lin_psi);
218  if(test_fg)
219  nfft_finalize(&p_fg_psi);
220  nfft_finalize(&p_pre_phi_hut);
221  nfft_finalize(&p);
222 
223  if(test_ndft)
224  nfft_free(swapndft);
225 }
226 
227 static void accuracy_pre_lin_psi(int d, int N, int M, int n, int m, int K)
228 {
229  int r, NN[d], nn[d];
230  double e;
231  double _Complex *swapndft;
232 
233  nfft_plan p;
234 
235  for(r=0; r<d; r++)
236  {
237  NN[r]=N;
238  nn[r]=n;
239  }
240 
242  swapndft=(double _Complex*)nfft_malloc(M*sizeof(double _Complex));
243 
244  nfft_init_guru(&p, d, NN, M, nn, m,
245  MALLOC_X| MALLOC_F_HAT| MALLOC_F|
246  PRE_PHI_HUT| PRE_LIN_PSI|
247  FFTW_INIT| FFT_OUT_OF_PLACE,
248  FFTW_MEASURE| FFTW_DESTROY_INPUT);
249 
251  nfft_free(p.psi);
252  p.K=K;
253  p.psi=(double*) nfft_malloc((p.K+1)*p.d*sizeof(double));
254 
256  nfft_precompute_one_psi(&p);
257 
260 
263 
265  NFFT_SWAP_complex(p.f,swapndft);
266  nfft_trafo_direct(&p);
267  NFFT_SWAP_complex(p.f,swapndft);
268 
270  nfft_trafo(&p);
271  e=X(error_l_2_complex)(swapndft, p.f, p.M_total);
272 
273  // printf("%d\t%d\t%d\t%d\t%.2e\n",d,N,m,K,e);
274  printf("$%.1e$&\t",e);
275 
276  fflush(stdout);
277 
279  nfft_finalize(&p);
280  nfft_free(swapndft);
281 }
282 
283 
284 int main(int argc,char **argv)
285 {
286  int l,m,d,trial,N;
287 
288  if(argc<=2)
289  {
290  fprintf(stderr,"flags type first last trials d m\n");
291  return -1;
292  }
293 
294  if((test==0)&&(atoi(argv[1])<2))
295  {
296  fprintf(stderr,"MEASURE_TIME in nfft3util.h not set\n");
297  return -1;
298  }
299 
300  fprintf(stderr,"Testing different precomputation schemes for the nfft.\n");
301  fprintf(stderr,"Columns: d, N=M, t_ndft, e_nfft, t_D, t_pre_phi_hut, ");
302  fprintf(stderr,"t_fftw, t_B, t_fg_psi, t_pre_lin_psi, t_pre_fg_psi, ");
303  fprintf(stderr,"t_pre_psi, t_pre_full_psi\n\n");
304 
305  d=atoi(argv[5]);
306  m=atoi(argv[6]);
307 
308  /* time vs. N=M */
309  if(atoi(argv[1])==0)
310  for(l=atoi(argv[2]); l<=atoi(argv[3]); l++)
311  for(trial=0; trial<atoi(argv[4]); trial++)
312  {
313  if(l<=20)
314  time_accuracy(d, (1U<< l), (1U<< (d*l)), (1U<< (l+1)), m, 0, 0);
315  else
316  time_accuracy(d, (1U<< l), (1U<< (d*l)), (1U<< (l+1)), m, 0, 0);
317  }
318 
319  d=atoi(argv[5]);
320  N=atoi(argv[6]);
321 
322  /* accuracy vs. time */
323  if(atoi(argv[1])==1)
324  for(m=atoi(argv[2]); m<=atoi(argv[3]); m++)
325  for(trial=0; trial<atoi(argv[4]); trial++)
326  time_accuracy(d, N, (int)pow(N,d), 2*N, m, 1, 1);
327 
328  d=atoi(argv[5]);
329  N=atoi(argv[6]);
330  m=atoi(argv[7]);
331 
332  /* accuracy vs. K for linear interpolation, assumes (m+1)|K */
333  if(atoi(argv[1])==2)
334  {
335  printf("$\\log_2(K/(m+1))$&\t");
336  for(l=atoi(argv[2]); l<atoi(argv[3]); l++)
337  printf("$%d$&\t",l);
338 
339  printf("$%d$\\\\\n",atoi(argv[3]));
340 
341  printf("$\\tilde E_2$&\t");
342  for(l=atoi(argv[2]); l<=atoi(argv[3]); l++)
343  accuracy_pre_lin_psi(d, N, (int)pow(N,d), 2*N, m, (m+1)*(1U<< l));
344 
345  printf("\n");
346  }
347 
348  return 1;
349 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1