Output of 2DFFT is not matching when dimensions of size 128*128, 256*256,512*512

Output of 2DFFT is not matching when dimensions of size 128*128, 256*256,512*512


I have written a program to check the correctness of 2D FFT using two different menthods.

First one has input data in complex format(real and imaginary are interlevaed).

2nd one has input data in de-interved format(two seperate arrays of real and imaginary parts).

we have two different routines available in MKL to solve this purpose. I found that the outputs are not mathcing using these routines when input size is 128*128, 256*256, 512*512,....

I included the code below. Please have a look and let me know if i do any mistake.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <complex>
#define MKL_Complex8 std::complex<float>
#include "mkl_dfti.h"
#include "mkl.h"

int main(int argc, char* argv[])
int N1 = atoi(argv[1]);
int N2 = atoi(argv[2]);
MKL_LONG status = 0;
 MKL_Complex8 *x = 0;
 MKL_Complex8 *y = 0;
 MKL_Complex8 *z = 0;
float* real;
float* imag;
float* real1;
float* imag1;
MKL_LONG N[2]; N[0] = N1; N[1] = N2;
        status = DftiCreateDescriptor(&hand, DFTI_SINGLE, DFTI_COMPLEX, 2, N);
if (0 != status) printf("failed\n");
status = DftiSetValue( hand, DFTI_PLACEMENT, DFTI_INPLACE );
if (0 != status) printf("failed\n");
status = DftiCommitDescriptor(hand);
if (0 != status) printf("failed\n");
x = (MKL_Complex8*)malloc(N1*N2*sizeof(MKL_Complex8));

real = (float*)malloc(N1*N2*sizeof(float));
imag = (float*)malloc(N1*N2*sizeof(float));

status = DftiCreateDescriptor(&hand1, DFTI_SINGLE, DFTI_COMPLEX, 2,N);
if (0 != status) printf("failed\n");
status = DftiSetValue(hand1, DFTI_COMPLEX_STORAGE, DFTI_REAL_REAL);
if (0 != status) printf("failed\n");
status = DftiCommitDescriptor(hand1);
if (0 != status) printf("failed\n");
for(int i = 0; i < N1*N2; i++)
x[i].real() =(float) i;
real[i] = i;
imag[i] = i+1;
x[i].imag() = (float)(i+1);
printf("before FFT\n");

for(int i =0 ; i < N1*N2; i++)
//printf(" (%f, %f)----------(%f, %f)\n",x[i].real(),x[i].imag(),real[i],imag[i]);
status = DftiComputeForward(hand, x);
if (0 != status) printf("failed\n");
status = DftiComputeForward(hand1,real, imag);
printf("after FFT prints if value not matches\n");

for(int i =0 ; i < N1*N2; i++)
    if(x[i].real()!= real[i] || x[i].imag() != imag[i])
    printf("not matching  %d -- (%f, %f)--------(%f, %f)\n",i,x[i].real(),x[i].imag(),real[i],imag[i]);



complie command: icc checkFFT.cpp -o checkFFT.o -mkl.

./checkFFT 128 128






3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello, shiva rama krishna bharadwaj I.

Very strange - when I tried to use your code, it passed (as it supposed to do). I tested it on linux ia32 and intel64. Could you please share what mkl version do you use and the platform?

Hi Evarist Fomenko,

I am using Intel MKL 11.1.2 version on linux 64 bit kernel version 2.6.32-358.el6.x86_64. It seems it is a bug in 11.1.2 version. when i tried with MKL 11.0.1 the code was working. 



Leave a Comment

Please sign in to add a comment. Not a member? Join today