fortran - gfortran 与 MKL 的链接导致 'Intel MKL ERROR: Parameter 10 was incorrect on entry to DGEMM'

标签 fortran gfortran blas intel-mkl

我有以下 Fortran 代码(在堆栈溢出的许多答案之上进行了修改......)

Program blas

    integer, parameter :: dp = selected_real_kind(15, 307)
  
    Real( dp ), Dimension( :, :    ), Allocatable :: a
    Real( dp ), Dimension( :, :, : ), Allocatable :: b
    Real( dp ), Dimension( :, :, : ), Allocatable :: c1, c2
  
    Integer :: na, nb, nc, nd, ne
    Integer :: la, lb, lc, ld  
  
  
    
    Write( *, * ) 'na, nb, nc, nd ?'
    Read( *, * ) na, nb, nc, nd
    ne = nc * nd
    Allocate( a ( 1:na, 1:nb ) ) 
    Allocate( b ( 1:nb, 1:nc, 1:nd ) ) 
    Allocate( c1( 1:na, 1:nc, 1:nd ) )   
    Allocate( c2( 1:na, 1:nc, 1:nd ) )
  
  
    Call Random_number( a )
    Call Random_number( b )
    c1 = 0.0_dp
    c2 = 0.0_dp

    do ld = 1, nd 
        do lc = 1, nc
          do lb = 1, nb
            do la = 1, na
              c1(la,lc,ld) = c1(la,lc,ld)  + a(la,lb) * b(lb, lc, ld)
            end do  
          end do
        end do
      end do  
  

    Call dgemm( 'N', 'N', na, ne, nb, 1.0_dp, a , Size( a , Dim = 1 ), &
                                              b , Size( b , Dim = 1 ), &
                                              0.0_dp, c2, Size( c2, Dim = 1 ) )


    do la = 1, na
      do lc = 1, nc
        do ld = 1, nd


        if ( dabs(c2(la,lc,ld) - c1(la,lc,ld))  > 1.e-6 ) then 
          write (*,*) '!!! c2', la,lc,ld, c2(la,lc,ld) - c1(la,lc,ld)
        endif      
         
        enddo
      enddo
    enddo  
  
  End 

(将其命名为 test.f90)。

它通过 gfortran -O3 test.f90 -L/opt/OpenBLAS/lib -lopenblas 工作。然后,我尝试将 gfortran 链接到 mkl,由 https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html 建议

gfortran -O3 test.f90 -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_gf_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ld。我得到了 Intel MKL 错误:进入 DGEMM 时参数 10 不正确。

我的问题是,参数 10 有什么问题?以及如何解决?看来如果我用ifort加上-mkl,就不会出现上面的问题。

最佳答案

您选择了 ilp64 版本的 MKL。这意味着整数、长整型和指针是 64 位的。但是您没有将 gfortran 与 64 位整数一起使用,我知道的所有编译器中的默认值都是 32 位整数。您想要不同版本的 MKL,例如 lp64,或者您想要将 gfortran 设置为使用 64 位默认整数。对于前者,在Link Advisor中选择32位整数接口(interface)层。

enter image description here

另见 https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models

关于fortran - gfortran 与 MKL 的链接导致 'Intel MKL ERROR: Parameter 10 was incorrect on entry to DGEMM',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70429724/

相关文章:

c++ - 在 C++ 中使用库 "xtensor-blas"时出错

file-io - 并行读取多个文件并将它们存储在共享变量中

casting - 参数类型问题

fortran - Fortran 中的重载赋值运算符和 ELEMENTAL 赋值运算符

compiler-errors - 模块和旧版 Fortran 77 代码

r - 由qr.Q()迷惑:什么是“紧凑”形式的正交矩阵?

concurrency - 有没有一种简单的方法可以使用 Fortran 中的随机数生成器进行并发计算?

fortran - 为什么这是一个在模块内部声明的函数,然后在链接器看不到的同一模块中的其他地方使用?

symlink - ld : library not found for -lgfortran - Mac Symlink issue?

c++ - "error LINK2019: unresolved..."