Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Zonglin_G_
Beginner
97 Views

Getting different output when calling the same FFT functions of MKL from C++ and Fortran

Jump to solution
I got different results when calling same functions of MKL from intel C++ compiler and IVF separately. I'm in windows 10 64bit, and VS 2013. My C++ code is as follows:
#include <complex>
#include <iostream>
#include "mkl_dfti.h"
int main()
{
 using namespace std;
 complex <float>x[32];
 int  i;
 DFTI_DESCRIPTOR_HANDLE my_desc1_handle;
 MKL_LONG status;
 for (i = 0; i < 32; i++)
 {
  x = ((i+1)*1.0, (i+1)*1.0);
 }
 status = DftiCreateDescriptor(&my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, 32);
 status = DftiCommitDescriptor(my_desc1_handle);
 status = DftiComputeForward(my_desc1_handle, x);
 status = DftiFreeDescriptor(&my_desc1_handle);
 for (i = 0; i < 32; i++)
 {
  cout << x << endl;
 }
 return 0;
}
My fortran code is as follows:
PROGRAM MAIN
    USE MKL_DFTI
    IMPLICIT NONE
    Complex :: X(32)
    INTEGER ::   I
    type(DFTI_DESCRIPTOR), POINTER :: My_Desc1_Handle
    Integer :: Status
    DO I=1,32
        X(I)=CMPLX(1d0*i,1d0*i)
    END DO
    Status = DftiCreateDescriptor( My_Desc1_Handle, DFTI_SINGLE, DFTI_COMPLEX, 1, 32 )
    Status = DftiCommitDescriptor( My_Desc1_Handle )
    Status = DftiComputeForward( My_Desc1_Handle, X )
    Status = DftiFreeDescriptor(My_Desc1_Handle)
    DO I=1,32
        write(*,*)x(i)
    END DO
    END
And results from these two programs are listed in the following columns. Left from C++, and right column from fortran.
(528,0)                    (528.0000,528.0000)     
(-16,162.451)          (-178.4507,146.4507)    
(-16,80.4374)          (-96.43743,64.43743)    
(-16,52.7449)          (-68.74493,36.74493)    
(-16,38.6274)          (-54.62742,22.62742)    
(-16,29.9339)          (-45.93389,13.93389)    
(-16,23.9457)          (-39.94569,7.945690)    
(-16,19.4961)          (-35.49606,3.496048)    
(-16,16)                   (-32.00000,0.0000000E+00)
(-16,13.1309)          (-29.13086,-2.869139)   
(-16,10.6909)          (-26.69086,-5.309141)   
(-16,8.55218)          (-24.55218,-7.447823)   
(-16,6.62742)          (-22.62742,-9.372583)   
(-16,4.85355)          (-20.85354,-11.14646)   
(-16,3.1826)           (-19.18260,-12.81741)   
(-16,1.57586)          (-17.57586,-14.42414)   
(-16,0)                     (-16.00000,-16.00000)   
(-16,-1.57586)         (-14.42414,-17.57586)   
(-16,-3.18259)         (-12.81741,-19.18260)   
(-16,-4.85355)         (-11.14646,-20.85355)   
(-16,-6.62742)         (-9.372583,-22.62742)   
(-16,-8.55217)         (-7.447824,-24.55218)   
(-16,-10.6909)         (-5.309142,-26.69086)   
(-16,-13.1309)         (-2.869135,-29.13086)   
(-16,-16)                  (0.0000000E+00,-32.00000)
(-16,-19.4961)         (3.496052,-35.49606)    
(-16,-23.9457)         (7.945692,-39.94569)    
(-16,-29.9339)         (13.93390,-45.93390)    
(-16,-38.6274)         (22.62742,-54.62742)    
(-16,-52.7449)         (36.74493,-68.74493)    
(-16,-80.4374)         (64.43743,-96.43742)    
(-16,-162.451)         (146.4507,-178.4507)    
Could someone enlighten me on this? I'm really obsessed with it. Thanks
 
 
 
 
 
0 Kudos
1 Solution
Evgueni_P_Intel
Employee
97 Views

Could you please also change initialization of the input array as follows?

for (i = 0; i < 32; i++)
{
  x = std::complex<float>((i+1)*1.0,(i+1)*1.0);
}

View solution in original post

7 Replies
Evgueni_P_Intel
Employee
97 Views

Hi Zonglin G!

Could you please check if casting 32 to MKL_LONG in the C++ code fixes the problem?

DftiCreateDescriptor is variadic, so the compiler cannot do this cast for you.

Evgueni.

Zonglin_G_
Beginner
97 Views

Evgueni Petrov aka espetrov (Intel) wrote:

Hi Zonglin G!

Could you please check if casting 32 to MKL_LONG in the C++ code fixes the problem?

DftiCreateDescriptor is variadic, so the compiler cannot do this cast for you.

Evgueni.

Thank you very much for your reply!

I happen to be a beginner. So I'm wondering if you could be more specific?

 

Evgueni_P_Intel
Employee
97 Views

Could you please add (MKL_LONG) so that DftiCreateDescriptor is called as follows?

status = DftiCreateDescriptor(&my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, (MKL_LONG)32);

 

Zonglin_G_
Beginner
97 Views

Evgueni Petrov aka espetrov (Intel) wrote:

Could you please add (MKL_LONG) so that DftiCreateDescriptor is called as follows?

status = DftiCreateDescriptor(&my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, (MKL_LONG)32);

 

Thank you for your patience with me.

I tried your suggestion, but the problem remains.

Evgueni_P_Intel
Employee
98 Views

Could you please also change initialization of the input array as follows?

for (i = 0; i < 32; i++)
{
  x = std::complex<float>((i+1)*1.0,(i+1)*1.0);
}

View solution in original post

Zonglin_G_
Beginner
97 Views

Evgueni Petrov aka espetrov (Intel) wrote:

Could you please also change initialization of the input array as follows?

for (i = 0; i < 32; i++)
{
  x = std::complex<float>((i+1)*1.0,(i+1)*1.0);
}

Yes, it works now!

I really appreicate your help!

But why should we explicitly specify "std::"? Is it meant to avoid some conflicts of name?  

Evgueni_P_Intel
Employee
97 Views

Yes, std:: can be omitted since 'using namespace std;' is present.

Reply