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