Beispiel #1
0
int main(int argc, char *argv[])
{
    cout.precision(16);
    int_t i, n = N;
    //cin >> n;
   
    typedef DFT TransformType;
    typedef ValueType::ValueType CT;

    TransformSet gfft;
    TransformSet::ObjectType* fftobj  = gfft.CreateTransformObject(n, ValueType::ID, TransformType::ID, 1, 
								   OpenMP<2>::ID, Place::ID);
    
// create sample data
    CT* data = new CT[n];
    CT* dataout = new CT[n];
    for (i=0; i < n; ++i) {
      // distribute in [-0.5;0.5] as in FFTW's benchmarks
       //data[i] = std::complex(rand()/(double)RAND_MAX - 0.5, rand()/(double)RAND_MAX - 0.5);
       data[i] = CT(2*i, 2*i+1); 
       dataout[i] = CT(0,0);
    }

    DFT_wrapper<CT::value_type> dft(data, n);

 // print out sample data
    cout<<"Input data:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[i].real()<<","<<data[i].imag()<<")"<<endl;

// apply FFT out-of-place
   fftobj->fft(data, dataout);

// do simple dft
   dft.apply();
    
   CT::value_type* dataout1 = dft.getdata();

// print out transformed data
   cout.precision(3);
   cout<<"Result of transform:"<<endl;
   for (i=0; i < n; ++i)
      cout<<"("<<dataout[i].real()<<","<<dataout[i].imag()<<")   \t("<<dataout1[2*i]<<","<<dataout1[2*i+1]<<") \t"<<endl;

   dft.diff(dataout);

   cout<<"Check against DFT:"<<endl;
   double mx(-1);
   for (i=0; i < n; ++i) {
      cout<<"("<<fabs(dataout[i].real())<<","<<fabs(dataout[i].imag())<<")"<<endl;
      mx = max(mx, fabs(dataout[i].real()));
      mx = max(mx, fabs(dataout[i].imag()));
   }
   cout<<"---------------------------------------------"<<endl;
   cout << mx << endl;
   
   delete [] data;
   delete [] dataout;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    unsigned int p = 2;
    typedef DFT TransformType;

    TransformSet gfft;
    TransformSet::ObjectType* fftobj  = gfft.CreateTransformObject(p, ValueType::ID, TransformType::ID, 1);
    TransformSet::ObjectType* ifftobj = gfft.CreateTransformObject(p, ValueType::ID, TransformType::Inverse::ID, 1);

    unsigned long i, n = (TransformType::ID == RDFT::ID) ? (1<<(p-1)) : (1<<p);

// create sample data
    ValueType::ValueType* data = new ValueType::ValueType [2*n];
    for (i=0; i < n; ++i) {
       data[2*i] = 2*i;
       data[2*i+1] = 2*i+1; //2*i+1;
    }

// print out sample data
    cout<<"Input data:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[2*i]<<","<<data[2*i+1]<<")"<<endl;

// apply FFT in-place
    fftobj->fft(data);

// print out transformed data
    cout<<"Result of transform:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[2*i]<<","<<data[2*i+1]<<")"<<endl;

    ifftobj->fft(data);

// print out transformed data
    cout<<"Result of backward transform:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[2*i]<<","<<data[2*i+1]<<")"<<endl;

}
Beispiel #3
0
int main(int /*argc*/, char** /*argv[]*/)
{
    cout.precision(16);
    long_t i;
   
    typedef DFT TransformType;
    typedef ValueType::ValueType T;
    typedef ValueType::base_type BT;
    static const int C = Loki::TypeTraits<T>::isStdFundamental ? 2 : 1;

    TransformSet gfft;
    TransformSet::ObjectType* fftobj  = gfft.CreateTransformObject(N, ValueType::ID, TransformType::ID, 1, 
								   OpenMP<NThreads>::ID, Place::ID);
//     TransformSet::ObjectType* ifftobj = gfft.CreateTransformObject(n, ValueType::ID, TransformType::Inverse::ID, 1, 
// 								   ParallelizationGroup::Default::ID, Place::ID);
    
// create sample data
    T* data = new T [C*N];
#if PLACE == OUT_OF_PLACE
    T* dataout = new T [C*N];
#endif
    for (i=0; i < N; ++i) {
//      GenInput<T>::rand(data, i);  // distribute in [-0.5;0.5] as in FFTW
       GenInput<T>::seq(data, i);
    }

    DFT_wrapper<BT> dft(data, N);

 // print out sample data
#ifdef FOUT
    cout<<"Input data:"<<endl;
    for (i=0; i < N; ++i)
      cout << GenOutput<T>(data,i) << endl;
#endif

#if PLACE == OUT_OF_PLACE
// apply FFT out-of-place
   fftobj->fft(data, dataout);
#else
// apply FFT in-place
   fftobj->fft(data);
   T* dataout = data;
#endif
   
// do simple dft
   dft.apply();

   BT* dataout1 = dft.getdata();

// print out transformed data
   cout.precision(3);
#ifdef FOUT
   cout<<"Result of transform:"<<endl;
   for (i=0; i < N; ++i)
     cout << GenOutput<T>(dataout,i) << "   \t"<< GenOutput<BT>(dataout1,i) <<" \t"<<endl;
#endif

   dft.diff(dataout);

   cout<<"Check against DFT:"<<endl;
   double mx(-1);
   double s = 0.;
   for (i=0; i < N; ++i) {
#ifdef FOUT
      cout << GenOutput<T>(dataout,i) << endl;
#endif
      double re = ComplexWrapper<T>(dataout,i).real();
      double im = ComplexWrapper<T>(dataout,i).imag();
      mx = max(mx, fabs(re));
      mx = max(mx, fabs(im));
      s += re*re;
      s += im*im;
   }
   cout<<"---------------------------------------------"<<endl;
   cout << N << ": " << ValueType::name() << ", " << Place::name() << endl;
   cout << mx << "  " << sqrt(s) << endl;

   delete [] data;
#if PLACE == OUT_OF_PLACE
   delete [] dataout;
#endif
}