Reputation: 305
I wanted to use FFTW split data and see its performance. So, I wrote this simple program basing on some examples that I've found on the internet.
The code is as follows:
#include <stdlib.h>
#include "defines.h"
#include <math.h>
#include <fftw3.h>
int main(void)
{
double *Xre, *Xim, *Yre, *Yim;
int N = 4096;
int i =0, j=0;
fftw_plan Plan;
fftw_iodim Dim;
Xre = fftw_malloc(sizeof(double) * N);
Xim = fftw_malloc(sizeof(double) * N);
Yre = fftw_malloc(sizeof(double) * N);
Yim = fftw_malloc(sizeof(double) * N);
for (i = 0; i < N; i++)
{
Xre[i] = input_data[2*i];
Xim[i] = input_data[2*i+1];
}
if(!(Plan = fftw_plan_guru_split_dft(1, &Dim, 0, NULL,Xre, Xim, Yre, Yim, FFTW_ESTIMATE)))
printf("FFTW3 failed to create plan.");
fftw_execute_split_dft(Plan, Xre, Xim, Yre, Yim);
printf("RESULTS:\n\n");
for (j = 0; j < N; j++)
{
printf("RE: %f,\tIM: %f \n", Yre[j], Yim[j]);
}
fftw_destroy_plan(Plan);
fftw_free(Xre);
fftw_free(Xim);
fftw_free(Yre);
fftw_free(Yim);
return 0;
}
where Xre and Xim refer to the inputs both reals and imaginaries, and Yre, Yim is for the results. The input_data
si declared in the defines.h
file like so:
float input_data[8192] ={
-7.418860e-02, 1.188460e-03 , -1.612460e-02 , -7.506560e-02,
7.372410e-02, -3.039230e-02 , 4.457970e-02 , 6.862750e-02,
-6.164490e-02, 5.634830e-02 , -6.556000e-02 , -5.147360e-02,
... , ... , ... , ... }
I did some debugging and it seems that the segmentation fault occurs in the execution line fftw_execute_split_dft(Plan, Xre, Xim, Yre, Yim)
. I've read this post fftw split example crashes. But, I still don't get the reason behind this error.
Upvotes: 0
Views: 359
Reputation: 140276
from the documentation:
fftw_plan fftw_plan_guru_split_dft(
int rank, const fftw_iodim *dims,
int howmany_rank, const fftw_iodim *howmany_dims,
double *ri, double *ii, double *ro, double *io,
unsigned flags);
You see that dims
is passed as a constant pointer. So it requires to be initialized with the actual dimension of your arrays (and the library cannot compute the size from an array by just passing the pointer)
the structure is as follows:
typedef struct {
int n;
int is;
int os;
} fftw_iodim;
Here, n is the size of the dimension, and is and os are the strides of that dimension for the input and output arrays. (The stride is the separation of consecutive elements along this dimension.)
So your plan is improperly initialized with random array sizes. I would initialize as follows before creating the plan:
Dim.n = N;
Dim.is = 1;
Dim.os = 1;
Upvotes: 3