<?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 Please ask this in the MKL in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156346#M27601</link>
    <description>&lt;P&gt;Please ask this in the MKL forum. It isn't a compiler question.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2019 00:49:55 GMT</pubDate>
    <dc:creator>Steve_Lionel</dc:creator>
    <dc:date>2019-12-17T00:49:55Z</dc:date>
    <item>
      <title>Matrix Inversion using Lapack (DGETRF/DGETRI)</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156345#M27600</link>
      <description>&lt;P&gt;I am trying to invert the following matrix using&amp;nbsp;DGETRF and&amp;nbsp;DGETRI&lt;/P&gt;&lt;P&gt;matrix =&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 0.50E+12 &amp;nbsp;0.00E+00 -0.30E+09 &amp;nbsp;0.25E+12 &amp;nbsp;0.00E+00 &amp;nbsp;0.10E-02 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 &amp;nbsp;0.12E+08 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.60E+07 -0.00E+00 -0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp;-0.30E+09 &amp;nbsp;0.00E+00 &amp;nbsp;0.48E+06 &amp;nbsp;0.00E+00 -0.00E+00 -0.00E+00 &amp;nbsp;0.30E+09 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.25E+12 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.10E+13 &amp;nbsp;0.00E+00 -0.00E+00 &amp;nbsp;0.25E+12 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 -0.60E+07 -0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.12E+08 -0.00E+00 &amp;nbsp;0.00E+00 -0.60E+07 -0.00E+00 -0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 -0.00E+00 -0.24E+06 -0.30E+09 &amp;nbsp;0.00E+00 &amp;nbsp;0.60E+04 &amp;nbsp;0.00E+00 -0.00E+00 -0.24E+06 &amp;nbsp;0.30E+09 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 -0.00E+00 &amp;nbsp;0.30E+09 &amp;nbsp;0.25E+12 &amp;nbsp;0.00E+00 -0.00E+00 &amp;nbsp;0.10E+13 &amp;nbsp;0.00E+00 -0.30E+09 &amp;nbsp;0.25E+12 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.60E+07 -0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.12E+08 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.60E+07 -0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.00E+00 -0.00E+00 -0.30E+09 &amp;nbsp;0.00E+00 &amp;nbsp;0.48E+06 &amp;nbsp;0.00E+00 -0.00E+00 &amp;nbsp;0.30E+09&lt;BR /&gt;&amp;nbsp; 0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.00E+00 -0.00E+00 &amp;nbsp;0.25E+12 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.10E+13 &amp;nbsp;0.00E+00 &amp;nbsp;0.25E+12&lt;BR /&gt;&amp;nbsp; 0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.10E-02 &amp;nbsp;0.00E+00 -0.60E+07 -0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.60E+07 &amp;nbsp;0.00E+00&lt;BR /&gt;&amp;nbsp; 0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 &amp;nbsp;0.00E+00 -0.10E-02 &amp;nbsp;0.00E+00 -0.00E+00 &amp;nbsp;0.30E+09 &amp;nbsp;0.25E+12 &amp;nbsp;0.00E+00 &amp;nbsp;0.50E+12&lt;/P&gt;&lt;P&gt;however it says the matrix is numerically singular.&amp;nbsp;However I can invert the matrix using excel/matlab with no problems&lt;/P&gt;&lt;P&gt;Does anyone have any idea why this is happening?&lt;/P&gt;&lt;P&gt;in the code below, the matrix is of size MJNT3xMJNT3 however I want to invert only the first NxN terms of S or Sinv.&lt;/P&gt;&lt;P&gt;I tried calling&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CALL DGETRF(N, N, Sinv, N, ipiv, info)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CALL DGETRI(N, Sinv, N, ipiv, work, N, info)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;it doesn't work. Then I tried a few other possibilities replacing the&amp;nbsp;LDA in both DGETRF and DGETRI from N to&amp;nbsp;MJNT3. and it didn't work either&lt;/P&gt;&lt;P&gt;I am not expert, so this is quite confusing to me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the whole subroutine is given below:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SUBROUTINE INVERT(S)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER MJNT,MJNT3&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; PARAMETER (MJNT=510,MJNT3=3*MJNT)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;! &amp;nbsp; &amp;nbsp; DECLARING GLOBAL VARIABLES&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; COMMON /CLIST21/ N,NJ3,M,NMT,NJ,NRJ,NR&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER N,NJ3,M,NMT,NJ,NRJ,NR !21 &amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;! &amp;nbsp; &amp;nbsp; DECLARING LOCAL VARIABLES&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER I,J !21 &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; REAL*8 S(MJNT3,MJNT3)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; REAL*8 Sinv(MJNT3,MJNT3)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER, DIMENSION(size(Sinv,1)) :: ipiv &amp;nbsp; ! pivot indices&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; real(dp), DIMENSION(size(Sinv,1)) :: work &amp;nbsp;! work array for LAPACK&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER :: info&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; EXTERNAL DGETRF&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; EXTERNAL DGETRI&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ! Store S in Sinv to prevent it from being overwritten by LAPACK&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DO 10 I=1,N&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DO 20 J=1,N&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Sinv(I,J) = S(I,J)&lt;BR /&gt;20 &amp;nbsp; &amp;nbsp;CONTINUE&lt;BR /&gt;10 &amp;nbsp; &amp;nbsp;CONTINUE&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ! DGETRF COMPUTES AN LU FACTORIZATION OF A GENERAL M-BY-N MATRIX A&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ! USING PARTIAL PIVOTING WITH ROW INTERCHANGES.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;CALL DGETRF(N, N, Sinv, N, ipiv, info)&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF (info /= 0) THEN&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; STOP 'MATRIX IS NUMERICALLY SINGULAR!'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; END IF &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ! DGETRI COMPUTES THE INVERSE OF A MATRIX USING THE LU FACTORIZATION&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ! COMPUTED BY DGETRF.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;CALL DGETRI(N, Sinv, N, ipiv, work, N, info)&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF (info /= 0) THEN&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; STOP 'MATRIX INVERSION FAILED!'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; END IF&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DO 30 I=1,N&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DO 40 J=1,N&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; S(I,J) = Sinv(I,J)&lt;BR /&gt;40 &amp;nbsp; &amp;nbsp;CONTINUE&lt;BR /&gt;30 &amp;nbsp; &amp;nbsp;CONTINUE&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; PAUSE !to test&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; RETURN&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; END&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 19:30:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156345#M27600</guid>
      <dc:creator>Neto__Conrado</dc:creator>
      <dc:date>2019-12-12T19:30:18Z</dc:date>
    </item>
    <item>
      <title>Please ask this in the MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156346#M27601</link>
      <description>&lt;P&gt;Please ask this in the MKL forum. It isn't a compiler question.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 00:49:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156346#M27601</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-12-17T00:49:55Z</dc:date>
    </item>
    <item>
      <title>As Steve wrote, this is a</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156347#M27602</link>
      <description>&lt;P&gt;As Steve wrote, this is a topic for the MKL forum.&lt;/P&gt;&lt;P&gt;Since SINV is not an N X N&amp;nbsp;matrix, the 4th argument to DGETRF and the 3rd argument to DGETRI are incorrect. Since N is in a common block, you need to ensure that N is set to the correct value before the subroutine is called.&lt;/P&gt;&lt;P&gt;Rather than trying arbitrary values for arguments, please read the MKL/Lapack documentation and pass the correct arguments to DGETRF and DGETRI.&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;      program calls
      real*8 s(1530,1530)
      call invert(s)
      write(*,10)((s(i,j),j=1,12),i=1,12)
   10 format(12ES11.3)
      end program
      
      subroutine invert(s)

      integer mjnt,mjnt3
      parameter (mjnt=510,mjnt3=3*mjnt)

!     declaring global variables
      integer n  

!     declaring local variables
      integer i,j !21  

      real*8 s(mjnt3,mjnt3)
      real*8 sinv(mjnt3,mjnt3)
      integer, dimension(size(sinv,1)) :: ipiv   ! pivot indices
      integer, parameter :: dp = selected_real_kind(15, 307)
      real(dp), dimension(size(sinv,1)) :: work  ! work array for lapack
      
      integer :: info
      
      external dgetrf
      external dgetri
      
      n=12
      read(*,*)((s(i,j),j=1,n),i=1,n)
      ! store s in sinv to prevent it from being overwritten by lapack
      do 10 i=1,n
      do 20 j=1,n
      sinv(i,j) = s(i,j)
20    continue
10    continue
      
      ! dgetrf computes an lu factorization of a general m-by-n matrix a
      ! using partial pivoting with row interchanges.
      call dgetrf(n, n, sinv, mjnt3, ipiv, info)
      if (info /= 0) then
          stop 'matrix is numerically singular!'
      end if      
      ! dgetri computes the inverse of a matrix using the lu factorization
      ! computed by dgetrf.
      call dgetri(n, sinv, mjnt3, ipiv, work, n, info)
      if (info /= 0) then
          stop 'matrix inversion failed!'
      end if
      
      do 30 i=1,n
      do 40 j=1,n
      s(i,j) = sinv(i,j)
40    continue
30    continue
      
      
      return
      end
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 17:02:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156347#M27602</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2019-12-17T17:02:12Z</dc:date>
    </item>
    <item>
      <title>or look at the dgetrix.f </title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156348#M27603</link>
      <description>&lt;P&gt;or look at the&amp;nbsp;dgetrix.f&amp;nbsp; examples from mklroot/examples/lapackf/source directory and plus this link to the MKL Developer Reference -&amp;nbsp;https://software.intel.com/en-us/onemkl-developer-reference-fortran-getri&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2019 05:20:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Matrix-Inversion-using-Lapack-DGETRF-DGETRI/m-p/1156348#M27603</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2019-12-23T05:20:08Z</dc:date>
    </item>
  </channel>
</rss>

