AlphaF20
AlphaF20

Reputation: 603

gfortran links with MKL leads to 'Intel MKL ERROR: Parameter 10 was incorrect on entry to DGEMM'

I have the following Fortran code (modified on top of many answers from stack overflow..)

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 

(call it test.f90).

It works by gfortran -O3 test.f90 -L/opt/OpenBLAS/lib -lopenblas. Then, I tried to link gfortran to mkl, suggested by 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. And I got Intel MKL ERROR: Parameter 10 was incorrect on entry to DGEMM .

My question is, what's wrong with the parameter 10? and how to fix it? It seems if I use ifort with -mkl, the above problem does not appear.

Upvotes: 3

Views: 1213

Answers (1)

You selected the ilp64 version of MKL. That means that integers, longs and pointers are 64-bit. But you are not using gfortran with 64-bit integers, the default in all compilers I know is 32-bit integers. Either you want a different version of MKL, like lp64, or you want to set up your gfortran to use 64-bit default integers. For the former, select the 32bit-integer interface layer in the Link Advisor.

enter image description here

See also https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models

Upvotes: 3

Related Questions