I am doing a 2D FFT using FFTW3 library, my implementation (check the following code) works for small arrays. However, it gives me a 'segmentation fault' error for large array sizes (for e.g. n= 1024). Could you please let me know how to fix it?
#include <complex>
#include <iostream>
#include <fftw3.h>
int main()
{
const int n=10;
fftw_plan p;
std::complex<double> test_in[n][n],test_out[n][n];
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
test_in[i][j]=std::complex<double>(i,j);
}
}
auto *in = new std::complex<double>[n][n];
auto *out = new std::complex<double>[n][n];
in=&test_in[0];
out=&test_out[0];
p = fftw_plan_dft_2d(n,n,reinterpret_cast<fftw_complex*>(&(*in)[0]),reinterpret_cast<fftw_complex*>(&(*out)[0]),FFTW_FORWARD, FFTW_ESTIMATE);
std::cout<<std::endl;
fftw_execute(p);
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
std::cout<<test_out[i][j] ;
}
std::cout<<std::endl;
}
fftw_destroy_plan(p);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire