NFFT  3.3.0
nfft_benchomp_detail.c
1 /*
2  * Copyright (c) 2002, 2015 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 "nfft3.h"
28 #include "infft.h"
29 #ifdef _OPENMP
30 #include <omp.h>
31 #endif
32 
33 void bench_openmp(FILE *infile, int m, int psi_flag)
34 {
35  NFFT(plan) p;
36  int *N;
37  int *n;
38  int M, d, trafo_adjoint;
39  int t, j;
40  double re,im;
41  ticks t0, t1;
42  double tt_total, tt_preonepsi;
43 
44  fscanf(infile, "%d %d", &d, &trafo_adjoint);
45 
46  N = malloc(d*sizeof(int));
47  n = malloc(d*sizeof(int));
48 
49  for (t=0; t<d; t++)
50  fscanf(infile, "%d", N+t);
51 
52  for (t=0; t<d; t++)
53  fscanf(infile, "%d", n+t);
54 
55  fscanf(infile, "%d", &M);
56 
57 #ifdef _OPENMP
58  FFTW(import_wisdom_from_filename)("nfft_benchomp_detail_threads.plan");
59 #else
60  FFTW(import_wisdom_from_filename)("nfft_benchomp_detail_single.plan");
61 #endif
62 
64  NFFT(init_guru)(&p, d, N, M, n, m,
65  PRE_PHI_HUT| psi_flag | MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
66  FFTW_MEASURE| FFTW_DESTROY_INPUT);
67 
68 #ifdef _OPENMP
69  FFTW(export_wisdom_to_filename)("nfft_benchomp_detail_threads.plan");
70 #else
71  FFTW(export_wisdom_to_filename)("nfft_benchomp_detail_single.plan");
72 #endif
73 
74  for (j=0; j < p.M_total; j++)
75  {
76  for (t=0; t < p.d; t++)
77  fscanf(infile, "%lg", p.x+p.d*j+t);
78  }
79 
80  if (trafo_adjoint==0)
81  {
82  for (j=0; j < p.N_total; j++)
83  {
84  fscanf(infile, "%lg %lg", &re, &im);
85  p.f_hat[j] = re + _Complex_I * im;
86  }
87  }
88  else
89  {
90  for (j=0; j < p.M_total; j++)
91  {
92  fscanf(infile, "%lg %lg", &re, &im);
93  p.f[j] = re + _Complex_I * im;
94  }
95  }
96 
97  t0 = getticks();
99  if(p.flags & PRE_ONE_PSI)
100  NFFT(precompute_one_psi)(&p);
101  t1 = getticks();
102  tt_preonepsi = NFFT(elapsed_seconds)(t1,t0);
103 
104  if (trafo_adjoint==0)
105  NFFT(trafo)(&p);
106  else
107  NFFT(adjoint)(&p);
108  t1 = getticks();
109  tt_total = NFFT(elapsed_seconds)(t1,t0);
110 
111 #ifndef MEASURE_TIME
112  p.MEASURE_TIME_t[0] = 0.0;
113  p.MEASURE_TIME_t[2] = 0.0;
114 #endif
115 
116 #ifndef MEASURE_TIME_FFTW
117  p.MEASURE_TIME_t[1] = 0.0;
118 #endif
119 
120  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);
121 // printf("%.6e\n", tt);
122 
123  free(N);
124  free(n);
125 
127  NFFT(finalize)(&p);
128 }
129 
130 int main(int argc, char **argv)
131 {
132  int m, psi_flag;
133 #ifdef _OPENMP
134  int nthreads;
135 
136  if (argc != 4)
137  return 1;
138 
139  nthreads = atoi(argv[3]);
140  FFTW(init_threads)();
141  omp_set_num_threads(nthreads);
142 #else
143  if (argc != 3)
144  return 1;
145 #endif
146 
147  m = atoi(argv[1]);
148  psi_flag = atoi(argv[2]);
149 
150  bench_openmp(stdin, m, psi_flag);
151 
152  return 0;
153 }