fortran - gfortran 与 MKL 的链接导致 'Intel MKL ERROR: P

我有以下 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)层。

另见 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# - 在 Visual Studio 中替换后删除空行

c++ - 无法构建 Boost Spirit 示例 conjure2

ios - FaSTLane Match 环境变量未被 build_app 获取

reactjs - 如何在 React 中使用 map 输出嵌套对象的内容?

java - ThreadPoolExecutor.shutdownNow() 没有在 Thread

typescript - 数组中泛型的联合

ruby-on-rails - 无法使用 octokit 连接到 Github 帐户

pytorch - Pytorch 中软标签的交叉熵

android - 我们如何保存和恢复 Android StateFlow 的状态?

javascript - Typescript reducer 的 switch case type