Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
70 Views

Cannot Invert Matrix using Lapack DGETRF/DGETRI in VBA

Hello guys,

I am trying to invert matrix in VBA Excel 32bit by using Lapack DGETRF/DGETRI function from mkl_rt.dll, which placed in "compilers_and_libraries_2020.1.216\windows\redist\ia32_win\mkl" folder.  

1. The issue is the Excel always quietly quits when the call is made.

2. I have just used the default mkl_rt.dll after install the MKL 2020 on my machine.

3. I follow this link and put all the dll together, but it still does not work:

https://stackoverflow.com/questions/42181563/declaring-blas-functions-from-intel-mkl-dll-in-vba-exce...

4. I read some comments that I need to use STDCALL, however, I cannot find the method to use this function.

The Declare:

 

 

Private Declare Function dgetrf Lib "*path\mkl_rt.dll" _
 (ByVal N As Integer, _
     ByVal M As Integer, _
     ByRef A As Double, _
     ByRef LDA As Integer, _
     ByRef IPIV As Integer, _
    ByRef INFO As Integer)

    Private Declare Function dgetri Lib "*path\mkl_rt.dll" _
    (ByVal N As Integer, _
    ByRef A As Double, _
    ByRef LDA As Integer, _
    ByRef IPIV As Integer, _
    ByRef WORK As Double, _
    ByRef LWORK As Integer, _
    ByRef INFO1 As Integer)

 

 

 

The using Subject

 

 

Public Sub NewMatrixSolver(ByVal Matrix1 As Matrix)

Dim M, N, LDA,  As Integer
Dim INFO,INFO1  As Integer
Dim A() As Double
Dim IPIV() As Integer

Dim i As Long
Dim j As Long

'' copy value from matrix1 to A array
ReDim A(1 To MRows, 1 To MCols) As Double
For i = 1 To MRows
 For j = 1 To MCols
  A(i, j) = Matrix1.GetValue(i, j) '' in-house function - tested
 Next
Next

ReDim IPIV(1 To MRows) As Integer
For i = 1 To MRows
 IPIV(i) = 0
Next

''CALL recursive LU algorithm
M = MRows
N = MCols
LDA = MRows
INFO = 0

Call dgetrf(M, N, A(1, 1), LDA, IPIV(1), INFO)

If INFO <> 0 Then
 MsgBox ("Error: Unable to invert matrix.")
 Stop
End If

''CALL inverse of a matrix using the LU factorization
LWORK = MRows
INFO1 = 0
Call dgetri(N, A(1, 1), LDA, IPIV(1), WORK, LWORK, INFO1)

If INFO1 <> 0 Then
 MsgBox ("Error: Unable to invert matrix.")
 Stop
End If

'' Use inverted Matrix A

end sub

 

 

 The dgetrf , dgetri

Please let me know if you guys need more information.

PS: I used to post this question in the post below when using dll built from Netlib and I will update the post after solving this issue.

https://software.intel.com/en-us/comment/1960703#

 

Thank you for reading.

0 Kudos