benchFFT.cpp File Reference
#include <iostream>
#include <bench/BenchUtil.h>
#include <complex>
#include <vector>
#include <Eigen/Core>
#include <unsupported/Eigen/FFT>

Macros

#define TYPE   float
 
#define NFFT   1024
 
#define NDATA   1000000
 

Functions

template<typename T >
string nameof ()
 
template<>
string nameof< float > ()
 
template<>
string nameof< double > ()
 
template<>
string nameof< long double > ()
 
template<typename T >
void bench (int nfft, bool fwd, bool unscaled=false, bool halfspec=false)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ NDATA

#define NDATA   1000000

◆ NFFT

#define NFFT   1024

◆ TYPE

#define TYPE   float

Function Documentation

◆ bench()

template<typename T >
void bench ( int  nfft,
bool  fwd,
bool  unscaled = false,
bool  halfspec = false 
)
52  {
53  typedef typename NumTraits<T>::Real Scalar;
54  typedef typename std::complex<Scalar> Complex;
55  int nits = NDATA / nfft;
56  vector<T> inbuf(nfft);
57  vector<Complex> outbuf(nfft);
58  FFT<Scalar> fft;
59 
60  if (unscaled) {
61  fft.SetFlag(fft.Unscaled);
62  cout << "unscaled ";
63  }
64  if (halfspec) {
65  fft.SetFlag(fft.HalfSpectrum);
66  cout << "halfspec ";
67  }
68 
69  std::fill(inbuf.begin(), inbuf.end(), 0);
70  fft.fwd(outbuf, inbuf);
71 
73  timer.reset();
74  for (int k = 0; k < 8; ++k) {
75  timer.start();
76  if (fwd)
77  for (int i = 0; i < nits; i++) fft.fwd(outbuf, inbuf);
78  else
79  for (int i = 0; i < nits; i++) fft.inv(inbuf, outbuf);
80  timer.stop();
81  }
82 
83  cout << nameof<Scalar>() << " ";
84  double mflops = 5. * nfft * log2((double)nfft) / (1e6 * timer.value() / (double)nits);
86  cout << "complex";
87  } else {
88  cout << "real ";
89  mflops /= 2;
90  }
91 
92  if (fwd)
93  cout << " fwd";
94  else
95  cout << " inv";
96 
97  cout << " NFFT=" << nfft << " " << (double(1e-6 * nfft * nits) / timer.value()) << " MS/s " << mflops << "MFLOPS\n";
98 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define NDATA
Definition: benchFFT.cpp:46
SCALAR Scalar
Definition: bench_gemm.cpp:45
Definition: BenchTimer.h:55
std::complex< RealScalar > Complex
Definition: common.h:71
char char char int int * k
Definition: level2_impl.h:374
double timer
Definition: oomph_metis_from_parmetis_3.1.1/struct.h:210
Scalar log2(Scalar x)
Definition: packetmath.cpp:754
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217

References e(), i, k, log2(), and NDATA.

◆ main()

int main ( int argc  ,
char **  argv 
)
100  {
101  bench<complex<float> >(NFFT, true);
102  bench<complex<float> >(NFFT, false);
103  bench<float>(NFFT, true);
104  bench<float>(NFFT, false);
105  bench<float>(NFFT, false, true);
106  bench<float>(NFFT, false, true, true);
107 
108  bench<complex<double> >(NFFT, true);
109  bench<complex<double> >(NFFT, false);
110  bench<double>(NFFT, true);
111  bench<double>(NFFT, false);
112  bench<complex<long double> >(NFFT, true);
113  bench<complex<long double> >(NFFT, false);
114  bench<long double>(NFFT, true);
115  bench<long double>(NFFT, false);
116  return 0;
117 }
#define NFFT
Definition: benchFFT.cpp:43

References NFFT.

◆ nameof()

template<typename T >
string nameof ( )

◆ nameof< double >()

template<>
string nameof< double > ( )
30  {
31  return "double";
32 }

◆ nameof< float >()

template<>
string nameof< float > ( )
26  {
27  return "float";
28 }

◆ nameof< long double >()

template<>
string nameof< long double > ( )
34  {
35  return "long double";
36 }