Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
- Cannot Invert Matrix using Lapack DGETRF/DGETRI in VBA

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

Ngo__Nhan

Novice

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-29-2020
04:37 AM

229 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:

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
```

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.

1 Reply

Highlighted
##

#

Ngo__Nhan

Novice

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-07-2020
10:57 AM

154 Views

I have an update about this issue:

After changing all ByVal into ByRef in both DGETRF/DGETR declaring, the 64bit DLL can work correctly with Excel 64bit.

However, when I'm moving on 32bit DLL and 32bit Excel, the **"Bad DLL calling convention (Error 49)"** appears. I used the build DLL by Intel mkl_2020 which is mkl_rt.dll, could anyone give instruction on how to fix this error?

Thank you a lot for reading

For more complete information about compiler optimizations, see our Optimization Notice.