Difference between real fft and complex fft with imaginary part of zero in fftw? I have a real 2d matrix. I am taking its fft using fftw. But the result of using a real to complex fft is different from a complex ( with imaginary part equal to zero) to complex fft. 

real matrix

 0     1     2
 3     4     5
 6     7     8


result of real to complex fft

36 -4.5+2.59808i  -13.5+7.79423i 
0  -13.5-7.79423i 0 
0  0              0 


Code:

int r = 3, c = 3;
int sz = r * c;
double *in = (double*) malloc(sizeof(double) * sz);
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * sz);
fftw_plan p = fftw_plan_dft_r2c_2d(r, c, in, out, FFTW_MEASURE);
for ( int i=0; i&lt;r; ++i ){
    for ( int j=0; j&lt;c; ++j ){
        in[i*c+j] = i*c + j;
    }
}
fftw_execute(p);


using a complex matrix with imaginary part of zero

complex matrix

 0+0i     1+0i     2+0i
 3+0i     4+0i     5+0i
 6+0i     7+0i     8+0i


result of complex to complex fft

36               -4.5 + 2.59808i  -4.5 - 2.59808i 
-13.5 + 7.79423i 0               0 
-13.5 - 7.79423i 0               0  


Code:

int r = 3, c = 3;
int sz = r * c;
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * sz);
fftw_complex *inc = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * sz);
p = fftw_plan_dft_2d( r,c, inc, out, FFTW_FORWARD,FFTW_MEASURE);
for ( int i=0; i&lt;r; ++i ){
    for ( int j=0; j&lt;c; ++j ){
        inc[i*c+j][0] = i*c+j;
        inc[i*c+j][1] = 0;
    }
}
fftw_execute(p);


I am after the result of complex to complex fft. But the real to complex fft is much faster and my data is real. Am I making a programming mistake or the result should be different?
I haven't tried this myself but I think it's just a problem of ordering the output data. In the real-to-complex case, your output matrix is not a $3\times 3$ matrix, but - due to the implied symmetry - a $3 \times 2$ matrix. So re-arranging your output gives

 36            -4.5+2.59808i
-13.5+7.79423i  0
-13.5-7.79423i  0  


where the "missing" third column would just be the complex conjugate of the second column. This is also explained here.