NFFT Logo 3.2.3
nfft_benchomp_detail.c
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: simple_test.c 3372 2009-10-21 06:04:05Z skunis $ */
20 
21 #include <stdio.h>
22 #include <math.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <complex.h>
26 
27 #include "nfft3util.h"
28 #include "nfft3.h"
29 #include "infft.h"
30 #ifdef _OPENMP
31 #include <omp.h>
32 #endif
33 
34 void bench_openmp(FILE *infile, int m, int psi_flag)
35 {
36  nfft_plan p;
37  int *N;
38  int *n;
39  int M, d, trafo_adjoint;
40  int t, j;
41  double re,im;
42  ticks t0, t1;
43  double tt_total, tt_preonepsi;
44 
45  fscanf(infile, "%d %d", &d, &trafo_adjoint);
46 
47  N = malloc(d*sizeof(int));
48  n = malloc(d*sizeof(int));
49 
50  for (t=0; t<d; t++)
51  fscanf(infile, "%d", N+t);
52 
53  for (t=0; t<d; t++)
54  fscanf(infile, "%d", n+t);
55 
56  fscanf(infile, "%d", &M);
57 
58 #ifdef _OPENMP
59  fftw_import_wisdom_from_filename("nfft_benchomp_detail_threads.plan");
60 #else
61  fftw_import_wisdom_from_filename("nfft_benchomp_detail_single.plan");
62 #endif
63 
65  nfft_init_guru(&p, d, N, M, n, m,
66  PRE_PHI_HUT| psi_flag | MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
67  FFTW_MEASURE| FFTW_DESTROY_INPUT);
68 
69 #ifdef _OPENMP
70  fftw_export_wisdom_to_filename("nfft_benchomp_detail_threads.plan");
71 #else
72  fftw_export_wisdom_to_filename("nfft_benchomp_detail_single.plan");
73 #endif
74 
75  for (j=0; j < p.M_total; j++)
76  {
77  for (t=0; t < p.d; t++)
78  fscanf(infile, "%lg", p.x+p.d*j+t);
79  }
80 
81  if (trafo_adjoint==0)
82  {
83  for (j=0; j < p.N_total; j++)
84  {
85  fscanf(infile, "%lg %lg", &re, &im);
86  p.f_hat[j] = re + _Complex_I * im;
87  }
88  }
89  else
90  {
91  for (j=0; j < p.M_total; j++)
92  {
93  fscanf(infile, "%lg %lg", &re, &im);
94  p.f[j] = re + _Complex_I * im;
95  }
96  }
97 
98  t0 = getticks();
100  if(p.nfft_flags & PRE_ONE_PSI)
101  nfft_precompute_one_psi(&p);
102  t1 = getticks();
103  tt_preonepsi = nfft_elapsed_seconds(t1,t0);
104 
105  if (trafo_adjoint==0)
106  nfft_trafo(&p);
107  else
108  nfft_adjoint(&p);
109  t1 = getticks();
110  tt_total = nfft_elapsed_seconds(t1,t0);
111 
112 #ifndef MEASURE_TIME
113  p.MEASURE_TIME_t[0] = 0.0;
114  p.MEASURE_TIME_t[2] = 0.0;
115 #endif
116 
117 #ifndef MEASURE_TIME_FFTW
118  p.MEASURE_TIME_t[1] = 0.0;
119 #endif
120 
121  printf("%.6e %.6e %6e %.6e %.6e %.6e\n", tt_preonepsi, p.MEASURE_TIME_t[0], p.MEASURE_TIME_t[1], p.MEASURE_TIME_t[2], tt_total-tt_preonepsi-p.MEASURE_TIME_t[0]-p.MEASURE_TIME_t[1]-p.MEASURE_TIME_t[2], tt_total);
122 // printf("%.6e\n", tt);
123 
124  free(N);
125  free(n);
126 
128  nfft_finalize(&p);
129 }
130 
131 int main(int argc, char **argv)
132 {
133  int m, psi_flag;
134 #ifdef _OPENMP
135  int nthreads;
136 
137  if (argc != 4)
138  return 1;
139 
140  nthreads = atoi(argv[3]);
141  fftw_init_threads();
142  omp_set_num_threads(nthreads);
143 #else
144  if (argc != 3)
145  return 1;
146 #endif
147 
148  m = atoi(argv[1]);
149  psi_flag = atoi(argv[2]);
150 
151  bench_openmp(stdin, m, psi_flag);
152 
153  return 0;
154 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1