Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Londhe__Ashutosh
Beginner
211 Views

Intel MKL FFT for forward and backward Fourier transform of 2D data

Jump to solution

Hello,

I am trying to do forward and backward Fourier transform using the FFT routines available in Intel MKL. I have taken help of manual and also website examples to do this but i am getting a segmentation fault. Please help me to resolve it. 

I am taking real valued as input to FFT forward and want output in Complex form.

 

Following is my code which i have implemented so far

#include <iostream>

#include "mkl_dfti.h"

typedef struct {
    float re;
    float im;
} mkl_float_complex;

using namespace std;

int main(int argc, char **argv)
{

//Read binary file in array xr_in dimension 2001 X 1911

n2=2001 n1=1911

    mkl_float_complex **xc_out;
    DFTI_DESCRIPTOR_HANDLE desc_handle_for, desc_handle_back;
    MKL_LONG status;
    MKL_LONG lengths[2];

    lengths[0] = n2;      lengths[1] = n1;
    xc_out = (mkl_float_complex**) malloc(sizeof(mkl_float_complex*)*n2);
    for(i2 = 0; i2 < n2; i2++)
        xc_out[i2] = (mkl_float_complex*) malloc(sizeof(mkl_float_complex)*n1);

    status = DftiCreateDescriptor(&desc_handle_for, DFTI_SINGLE, DFTI_REAL, 2, lengths);

    status = DftiSetValue(desc_handle_for, DFTI_CONJUGATE_EVEN_STORAGE, DFTI_COMPLEX_COMPLEX);

    status = DftiSetValue(desc_handle_for, DFTI_PACKED_FORMAT,          DFTI_CCE_FORMAT);

    status = DftiSetValue(desc_handle_for, DFTI_PLACEMENT,              DFTI_NOT_INPLACE);

    status = DftiCommitDescriptor(desc_handle_for);

    status = DftiComputeForward(desc_handle_for, xr_in, xc_out);

    status = DftiFreeDescriptor(&desc_handle_for);

     //Writing real part only to file

    //Open file

    for(i2 = 0; i2 < n2; i2++)
        for(i1 = 0; i1 < n1; i1++)
            fwrite(&(xc_out[i2][i1].re), sizeof(float), 1, fp);

   //Close file

}//End of main

   

     

 

 

 

0 Kudos
1 Solution
Zhen_Z_Intel
Employee
211 Views

Hi Ashutosh,

Please define input/output matrix as two dimentional array to replace using pointer. You must insure data is saved in continuous memory space.

Like:

mkl_float_complex xr_in[2001][1191];
    xr_in.re=...;
    xr_in.im=...;

View solution in original post

3 Replies
Zhen_Z_Intel
Employee
212 Views

Hi Ashutosh,

Please define input/output matrix as two dimentional array to replace using pointer. You must insure data is saved in continuous memory space.

Like:

mkl_float_complex xr_in[2001][1191];
    xr_in.re=...;
    xr_in.im=...;

View solution in original post

Londhe__Ashutosh
Beginner
211 Views

Dear Fiona Z,

The solution you provided worked.

Now no error, but i have written the real and imag part to separate file which shows only half of the portion and other half is zero in n1 dimension. Do i need to increase the number of transform. Or do i have to set any other value also apart from which are specified in code snippet. 

Thanks

 

Zhen_Z_Intel
Employee
211 Views

Hi Ashutosh,

You created descriptor that Forward domain of the transform is real not complex. image part would not be calculated. That's the reason you get all values of im with zero. Please refer developer reference: https://software.intel.com/en-us/node/521976

Reply