Quantcast
Channel: Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 2652

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

$
0
0

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] = ((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[i] << 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

 

 

 

 

 


Viewing all articles
Browse latest Browse all 2652

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>