Fortran Coder

标题: MKLFFT [打印本页]

作者: xxdw    时间: 2021-12-27 22:55
标题: MKLFFT
[Fortran] 纯文本查看 复制代码
    program TEST_FFTwithMatlab
    USE MKL_DFTI

    IMPLICIT NONE
    INTEGER*4::X_in_Len = 7
    COMPLEX*8::X_in(7)
    INTEGER*4::Dim=1,X_Len,Status,i
    REAL*8,DIMENSION(7)::a,b
    COMPLEX*8,DIMENSION(:),ALLOCATABLE::X_inout
    Type(DFTI_DESCRIPTOR), POINTER :: Desc_handle

    !------1
    X_Len = 7
    if(allocated(X_inout)) deallocate(X_inout)
    Allocate(X_inout(X_Len))
    a = (/0.34907d0,0.54890d0,0.74776d0,0.94459d0,1.13850d0,1.32850d0,1.51370d0/)
    b = 0d0
    X_inout = CMPLX(a,b)
    !------2
    !------fft
    X_in(1)=(0.34907D0,0D0)
    X_in(2)=(0.54890D0,0D0)
    X_in(3)=(0.74776D0,0D0)
    X_in(4)=(0.94459D0,0D0)
    X_in(5)=(1.13850D0,0D0)
    X_in(6)=(1.32850D0,0D0)
    X_in(7)=(1.51370D0,0D0)
    do i=1,7
        print*, X_in(i)
    end do
    Status = DftiCreateDescriptor (Desc_handle, DFTI_DOUBLE, DFTI_COMPLEX, Dim, X_Len)
    !Status = DftiGetValue(Desc_handle, DFTI_placement)
    !Status = DftiGetValue(Desc_handle, DFTI_Forward_Scale)
    Status = DftiSetValue(Desc_handle, DFTI_placement, dfti_inplace)
    Status = DftiCommitDescriptor (Desc_handle)
    Status = DftiComputeForward(Desc_handle, X_in)
    Status = DftiFreeDescriptor(Desc_handle)
    if (Status .ne. 0) then
        if (.not. DftiErrorClass(status,DFTI_NO_ERROR)) then
            print *, 'Error: ', Status, DftiErrorMessage(Status)
        endif
    endif
    !------ifft   
    PRINT *,X_in
    X_in(1)=(0.34907D0,0D0)
    X_in(2)=(0.54890D0,0D0)
    X_in(3)=(0.74776D0,0D0)
    X_in(4)=(0.94459D0,0D0)
    X_in(5)=(1.13850D0,0D0)
    X_in(6)=(1.32850D0,0D0)
    X_in(7)=(1.51370D0,0D0)
    do i=1,7
        print*, X_in(i)
    end do
    Status = DftiCreateDescriptor(Desc_handle, DFTI_DOUBLE, DFTI_COMPLEX, Dim, X_Len)
    Status = DftiSetValue(Desc_handle, DFTI_BACKWARD_SCALE, 1.0d0/X_Len)
    Status = DftiSetValue(Desc_handle, DFTI_placement, dfti_inplace)
    Status = DftiCommitDescriptor (Desc_handle)
    Status = DftiComputeBackward(Desc_handle, X_in)  !720,1
    Status = DftiFreeDescriptor(Desc_handle)
    if (Status .ne. 0) then
        if (.not. DftiErrorClass(status,DFTI_NO_ERROR)) then
            print *, 'Error: ', Status, DftiErrorMessage(Status)
        endif
    endif
    PRINT *,X_in/X_Len



    END PROGRAM


这段是使用MKL的FFT的代码,之前计算过而且FFT IFFT和matlab对比没有错误。
现在使用file:///C:\Users\Davy\AppData\Roaming\Tencent\Users\958256222\QQ\WinTemp\RichOle\$6~3JHLSA}UH__ULQEQ$3FV.png
Error:            5
Intel MKL DFTI ERROR: Descriptor is uncommitted or corrupted

会报这个错,请问是什么原因呢



作者: fcode    时间: 2021-12-28 08:13
complex*8 全部改成
complex(8)

complex*8 占用8个字节,实部虚部各4,是单精度!!
complex(8) 占用16个字节,实部虚部各8,是双精度

你用了 DFTI_DOUBLE,需要用双精度~!
当前不推荐使用 * 来定义变量的kind值。非常不推荐。
作者: xxdw    时间: 2021-12-28 13:02
fcode 发表于 2021-12-28 08:13
complex*8 全部改成
complex(8)

谢谢雪球老师!
刘涛最美!
作者: fcode    时间: 2021-12-28 14:09





欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2