<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Cannot Invert Matrix using Lapack DGETRF/DGETRI in VBA in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-Invert-Matrix-using-Lapack-DGETRF-DGETRI-in-VBA/m-p/1188023#M29646</link>
    <description>&lt;P&gt;Hello guys,&lt;/P&gt;
&lt;P&gt;I am trying to invert matrix in VBA Excel 32bit by using Lapack DGETRF/DGETRI function from&amp;nbsp;mkl_rt.dll, which placed in&amp;nbsp;"compilers_and_libraries_2020.1.216\windows\redist\ia32_win\mkl" folder.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. The issue is the Excel always quietly quits when the call is made.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. I have just used the default mkl_rt.dll after install the MKL 2020 on my machine.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. I follow this link and put all the dll together, but it still does not work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://stackoverflow.com/questions/42181563/declaring-blas-functions-from-intel-mkl-dll-in-vba-excel" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/42181563/declaring-blas-functions-from-intel-mkl-dll-in-vba-excel&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;4. I read some comments that I need to use STDCALL, however, I cannot find the method to use this function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The Declare:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The using Subject&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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 &amp;lt;&amp;gt; 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 &amp;lt;&amp;gt; 0 Then
 MsgBox ("Error: Unable to invert matrix.")
 Stop
End If

'' Use inverted Matrix A

end sub&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The &lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-factorization-lapack-computational-routines/getrf.html?wapkw=getrf" target="_self"&gt;d&lt;/A&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-factorization-lapack-computational-routines/getrf.html?wapkw=getrf" target="_self"&gt;getrf&lt;/A&gt;&amp;nbsp;, &lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-inversion-lapack-computational-routines/getri.html?wapkw=getri" target="_self"&gt;dgetri&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Please let me know if you guys need more information.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;PS: I used to post this question in the post below when using dll&amp;nbsp;&lt;SPAN&gt;built from Netlib and I will update the post after solving this issue.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;A href="https://software.intel.com/en-us/comment/1960703#" target="_blank" rel="noopener"&gt;https://software.intel.com/en-us/comment/1960703#&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Thank you for reading.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2020 16:12:11 GMT</pubDate>
    <dc:creator>Ngo__Nhan</dc:creator>
    <dc:date>2020-06-29T16:12:11Z</dc:date>
    <item>
      <title>Cannot Invert Matrix using Lapack DGETRF/DGETRI in VBA</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-Invert-Matrix-using-Lapack-DGETRF-DGETRI-in-VBA/m-p/1188023#M29646</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;
&lt;P&gt;I am trying to invert matrix in VBA Excel 32bit by using Lapack DGETRF/DGETRI function from&amp;nbsp;mkl_rt.dll, which placed in&amp;nbsp;"compilers_and_libraries_2020.1.216\windows\redist\ia32_win\mkl" folder.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. The issue is the Excel always quietly quits when the call is made.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. I have just used the default mkl_rt.dll after install the MKL 2020 on my machine.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. I follow this link and put all the dll together, but it still does not work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://stackoverflow.com/questions/42181563/declaring-blas-functions-from-intel-mkl-dll-in-vba-excel" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/42181563/declaring-blas-functions-from-intel-mkl-dll-in-vba-excel&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;4. I read some comments that I need to use STDCALL, however, I cannot find the method to use this function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The Declare:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The using Subject&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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 &amp;lt;&amp;gt; 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 &amp;lt;&amp;gt; 0 Then
 MsgBox ("Error: Unable to invert matrix.")
 Stop
End If

'' Use inverted Matrix A

end sub&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The &lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-factorization-lapack-computational-routines/getrf.html?wapkw=getrf" target="_self"&gt;d&lt;/A&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-factorization-lapack-computational-routines/getrf.html?wapkw=getrf" target="_self"&gt;getrf&lt;/A&gt;&amp;nbsp;, &lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-inversion-lapack-computational-routines/getri.html?wapkw=getri" target="_self"&gt;dgetri&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Please let me know if you guys need more information.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;PS: I used to post this question in the post below when using dll&amp;nbsp;&lt;SPAN&gt;built from Netlib and I will update the post after solving this issue.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;A href="https://software.intel.com/en-us/comment/1960703#" target="_blank" rel="noopener"&gt;https://software.intel.com/en-us/comment/1960703#&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Thank you for reading.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:12:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-Invert-Matrix-using-Lapack-DGETRF-DGETRI-in-VBA/m-p/1188023#M29646</guid>
      <dc:creator>Ngo__Nhan</dc:creator>
      <dc:date>2020-06-29T16:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Invert Matrix using Lapack DGETRF/DGETRI in VBA</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-Invert-Matrix-using-Lapack-DGETRF-DGETRI-in-VBA/m-p/1190345#M29708</link>
      <description>&lt;P&gt;I have an update about this issue:&lt;/P&gt;
&lt;P&gt;After changing all ByVal into ByRef in both&amp;nbsp;DGETRF/DGETR&amp;nbsp;d&lt;SPAN&gt;eclaring, the 64bit DLL can work correctly with Excel 64bit. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;However, when I'm moving on 32bit DLL and 32bit Excel, the &lt;STRONG&gt;"Bad DLL calling convention (Error 49)"&lt;/STRONG&gt; 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?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you a lot for reading&lt;/SPAN&gt;&lt;/P&gt;
&lt;H1 id="bad-dll-calling-convention-error-49"&gt;&amp;nbsp;&lt;/H1&gt;</description>
      <pubDate>Tue, 07 Jul 2020 17:57:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-Invert-Matrix-using-Lapack-DGETRF-DGETRI-in-VBA/m-p/1190345#M29708</guid>
      <dc:creator>Ngo__Nhan</dc:creator>
      <dc:date>2020-07-07T17:57:45Z</dc:date>
    </item>
  </channel>
</rss>

