Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

dgels acts strange..

ppthelion
Beginner
488 Views
Hi:
when I used dgels to solve my problem, the result showwederror. So I compile a new small program to test it :

program test_dgels

program test_dgels
!DEC$ OBJCOMMENT LIB:'mkl_solver_sequential.lib'
!DEC$ OBJCOMMENT LIB:'mkl_intel_c.lib'
!DEC$ OBJCOMMENT LIB:'mkl_sequential.lib'
!DEC$ OBJCOMMENT LIB:'mkl_core.lib'
!DEC$ OBJCOMMENT LIB:'mkl_lapack95.lib'
implicit none
! here we just check the subroutine dgels
! equation is 2x1+x2 = 3 / x1+2x2 = 5
integer ,parameter :: m = 2,n =2,nrhs =1
real*8 a(m,n),b(n,nrhs)
integer i,j,lwork,info,astat
integer,allocatable :: work(:)

lwork=min (m, n)+max(1, m, n, nrhs)
allocate(work(max(1,lwork)),stat =astat)
if(astat .NE. 0) then
print *,'work allocate error happen!'
endif

data a /2.d0,1.d0,1.d0,2.d0/
b =(3.d0,5.d0)
call dgels('N',2,2,1,a,2,b,2,work,lwork,info)
print *,a(1,1)*b(1,1)+a(1,2)*b(2,1)

deallocate(work,stat = astat)
if(astat .NE. 0) then
print *,'work deallocate error happen!'
endif
stop
end

the result was not 3.0 but 4.0
Why?
Any answer is appreciated,thanks!
P

0 Kudos
2 Replies
Gennady_F_Intel
Moderator
488 Views
Quoting - ppthelion
Hi:
when I used dgels to solve my problem, the result showwederror. So I compile a new small program to test it :

program test_dgels
!DEC$ OBJCOMMENT LIB:'mkl_solver_sequential.lib'
!DEC$ OBJCOMMENT LIB:'mkl_intel_c.lib'
!DEC$ OBJCOMMENT LIB:'mkl_sequential.lib'
!DEC$ OBJCOMMENT LIB:'mkl_core.lib'
!DEC$ OBJCOMMENT LIB:'mkl_lapack95.lib'
implicit none
! here we just check the subroutine dgels
! equation is 2x1+x2 = 3 / x2+2x1 = 5
real*8 a(2,2),b(2,1)
integer i,j,work,lwork,info
integer,parameter :: opt = 80

lwork=160
work = 180
data a /2.d0,1.d0,1.d0,3.d0/
b =(3.d0,5.d0)
call dgels('N',2,2,1,a,2,b,2,work,lwork,info)
print *,a(1,1)*b(1,1)+a(1,2)*b(2,1)
stop

end
But the result was not 3.0 but 4.0
Why?
Any answer is appreciated,thanks!
P

- the equations are the same, isn't it?
2x1+x2 = 3 / x2+2x1 = 5
- work is a workspace array, its dimension max(1, lwork).
will it help?

0 Kudos
ppthelion
Beginner
488 Views
This problem has been solved,Thanks !

0 Kudos
Reply