<?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 problem using c++ version of dgesv  in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830214#M5479</link>
    <description>please see the DGESV C Example &lt;A href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/index.htm"&gt;here&lt;/A&gt;.</description>
    <pubDate>Tue, 04 Jan 2011 19:02:55 GMT</pubDate>
    <dc:creator>Gennady_F_Intel</dc:creator>
    <dc:date>2011-01-04T19:02:55Z</dc:date>
    <item>
      <title>problem using c++ version of dgesv</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830212#M5477</link>
      <description>Dear all, &lt;BR /&gt;&lt;BR /&gt;please find below two times the same sample code. &lt;BR /&gt;Purpose is to to solve a system of linear equations of matrix A and matrix B. However, the resulting Matrix B differs. &lt;BR /&gt;The Fortran version gives the correct, the C++ a wrong result.&lt;BR /&gt;Can anyone tell me what is wrong with the C++ source?&lt;BR /&gt;&lt;BR /&gt;This is the (incorrect) C++ version:&lt;BR /&gt;&lt;PRE&gt;[cpp]#include "mkl.h"&lt;BR /&gt;#include &lt;MATH.H&gt;&lt;BR /&gt;#include &lt;IOSTREAM&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;#define NI 4&lt;BR /&gt;#define NJ 3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char* argv[])&lt;BR /&gt;{&lt;BR /&gt;	double a[NI][NI];&lt;BR /&gt;	double b[NI][NJ];&lt;BR /&gt;&lt;BR /&gt;	a[0][0] = 1;&lt;BR /&gt;	a[0][1] = 1;&lt;BR /&gt;	a[0][2] = 1;&lt;BR /&gt;	a[0][3] = 1;&lt;BR /&gt;	a[1][0] = 7.4895;&lt;BR /&gt;	a[1][1] = 7.5292;&lt;BR /&gt;	a[1][2] = 7.3905;&lt;BR /&gt;	a[1][3] = 7.4141;&lt;BR /&gt;	a[2][0] = 1.1759;&lt;BR /&gt;	a[2][1] = 1.2956;&lt;BR /&gt;	a[2][2] = 1.2342;&lt;BR /&gt;	a[2][3] = 1.3149;&lt;BR /&gt;	a[3][0] = 0.1496;&lt;BR /&gt;	a[3][1] = 0.3214;&lt;BR /&gt;	a[3][2] = 0.2887;&lt;BR /&gt;	a[3][3] = 0.1598;&lt;BR /&gt;&lt;BR /&gt;	b[0][0] = 0;&lt;BR /&gt;	b[0][1] = 0;&lt;BR /&gt;	b[0][2] = 0;&lt;BR /&gt;	b[1][0] = 1;&lt;BR /&gt;	b[1][1] = 0;&lt;BR /&gt;	b[1][2] = 0;&lt;BR /&gt;	b[2][0] = 0;&lt;BR /&gt;	b[2][1] = 1;&lt;BR /&gt;	b[2][2] = 0;&lt;BR /&gt;	b[3][0] = 0;&lt;BR /&gt;	b[3][1] = 0;&lt;BR /&gt;	b[3][2] = 1;&lt;BR /&gt;&lt;BR /&gt;	cout &amp;lt;&amp;lt; "A1 = \n";&lt;BR /&gt;	for(int i = 0; i &amp;lt; NI; i++)&lt;BR /&gt;	{&lt;BR /&gt;		for(int j = 0; j &amp;lt; NI; j++)&lt;BR /&gt;		{&lt;BR /&gt;			cout &amp;lt;&amp;lt; a&lt;I&gt;&lt;J&gt; &amp;lt;&amp;lt; "\t";&lt;BR /&gt;		}&lt;BR /&gt;		cout &amp;lt;&amp;lt; "\n";&lt;BR /&gt;	}&lt;BR /&gt;	cout &amp;lt;&amp;lt; "\n";&lt;BR /&gt;&lt;BR /&gt;	int ipiv[NI];&lt;BR /&gt;	for (int i = 0; i &amp;lt; NI; i++){&lt;BR /&gt;		ipiv&lt;I&gt; = 0;&lt;BR /&gt;	}&lt;BR /&gt;&lt;BR /&gt;	cout &amp;lt;&amp;lt; "B1 = \n";&lt;BR /&gt;	for(int i = 0; i &amp;lt; NI; i++)&lt;BR /&gt;	{&lt;BR /&gt;		for(int j = 0; j &amp;lt; NJ; j++)&lt;BR /&gt;		{&lt;BR /&gt;			cout &amp;lt;&amp;lt; b&lt;I&gt;&lt;J&gt; &amp;lt;&amp;lt; "\t";&lt;BR /&gt;		}&lt;BR /&gt;		cout &amp;lt;&amp;lt; "\n";&lt;BR /&gt;	}&lt;BR /&gt;	cout &amp;lt;&amp;lt; "\n";&lt;BR /&gt;	int n = NI;&lt;BR /&gt;	int nrhs = NJ;&lt;BR /&gt;	int lda = NI;&lt;BR /&gt;	int ldb = NI;&lt;BR /&gt;	int info = -1;&lt;BR /&gt;	dgesv(&amp;amp;n, &amp;amp;nrhs, *a, &amp;amp;lda, ipiv, *b, &amp;amp;ldb, &amp;amp;info);&lt;BR /&gt;&lt;BR /&gt;	cout &amp;lt;&amp;lt; "INFO = " &amp;lt;&amp;lt; info &amp;lt;&amp;lt; "\n";&lt;BR /&gt;&lt;BR /&gt;	cout &amp;lt;&amp;lt; "G = \n";&lt;BR /&gt;	cout.setf(std::ios::scientific);&lt;BR /&gt;	for(int i = 0; i &amp;lt; NI; i++)&lt;BR /&gt;	{&lt;BR /&gt;		for(int j = 0; j &amp;lt; NJ; j++)&lt;BR /&gt;		{&lt;BR /&gt;			cout &amp;lt;&amp;lt; b&lt;I&gt;&lt;J&gt; &amp;lt;&amp;lt; "\t";&lt;BR /&gt;		}&lt;BR /&gt;		cout &amp;lt;&amp;lt; "\n";&lt;BR /&gt;	}&lt;BR /&gt;	cout &amp;lt;&amp;lt; "\n";&lt;BR /&gt;&lt;BR /&gt;	return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;[/cpp]&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/IOSTREAM&gt;&lt;/MATH.H&gt;&lt;/PRE&gt; And here is the (correct) Fortran version:&lt;BR /&gt;&lt;PRE&gt;[fxfortran]      PROGRAMM TEST
      IMPLICIT NONE    

      DOUBLE PRECISION A(4,4), B(4,3)
      INTEGER N,NRHS,LDA,INFO,LDB,I,J
      DOUBLE PRECISION IPIV(4)
      
      N = 4
      NRHS = 3
      LDA = 4
      LDB = 4
      
 
      A(1,1) = 1
      A(1,2) = 1
      A(1,3) = 1
      A(1,4) = 1
      A(2,1) = 7.4895  
      A(2,2) = 7.5292  
      A(2,3) = 7.3905  
      A(2,4) = 7.4141
      A(3,1) = 1.1759  
      A(3,2) = 1.2956  
      A(3,3) = 1.2342  
      A(3,4) = 1.3149
      A(4,1) = 0.1496  
      A(4,2) = 0.3214  
      A(4,3) = 0.2887  
      A(4,4) = 0.1598

      B(1,1) = 0
      B(1,2) = 0
      B(1,3) = 0
      B(2,1) = 1
      B(2,2) = 0
      B(2,3) = 0
      B(3,1) = 0
      B(3,2) = 1
      B(3,3) = 0
      B(4,1) = 0
      B(4,2) = 0
      B(4,3) = 1

      DO I = 1, 4
      IPIV(I) = 0.0
      WRITE(*,'(4(F10.4))') (A(I,J), J = 1, 4)
      ENDDO
      
      DO I = 1, 4
      WRITE(*,'(4(F10.4))') (B(I,J), J = 1, 3)
      ENDDO
      
      CALL DGESV(N,NRHS,A,LDA,IPIV,B,LDB,INFO)
      
      WRITE(*,*) 'INFO = ', INFO
      
      DO I = 1, 4
      WRITE(*,'(4(F10.4))') (B(I,J), J = 1, 3)
      ENDDO
      
      END
[/fxfortran]&lt;/PRE&gt;    &lt;BR /&gt;&lt;BR /&gt;Kind regards&lt;BR /&gt;Wolfram&lt;BR /&gt;</description>
      <pubDate>Tue, 04 Jan 2011 17:17:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830212#M5477</guid>
      <dc:creator>geowolf</dc:creator>
      <dc:date>2011-01-04T17:17:53Z</dc:date>
    </item>
    <item>
      <title>problem using c++ version of dgesv</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830213#M5478</link>
      <description>C stores a matrix with row-1 first, then row-2,...&lt;BR /&gt;&lt;BR /&gt;Fortran stores a matrix with col-1 first, then col-2,...&lt;BR /&gt;&lt;BR /&gt;Unless your matrix is symmetric, you need to take these facts into consideration. Alternatively, use the C-Lapack interface which gives you wrappers around the Fortran routines with the ability to specify the storage order of the matrices, etc.</description>
      <pubDate>Tue, 04 Jan 2011 18:06:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830213#M5478</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2011-01-04T18:06:48Z</dc:date>
    </item>
    <item>
      <title>problem using c++ version of dgesv</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830214#M5479</link>
      <description>please see the DGESV C Example &lt;A href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/index.htm"&gt;here&lt;/A&gt;.</description>
      <pubDate>Tue, 04 Jan 2011 19:02:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830214#M5479</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2011-01-04T19:02:55Z</dc:date>
    </item>
    <item>
      <title>problem using c++ version of dgesv</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830215#M5480</link>
      <description>Dear all,&lt;BR /&gt;&lt;BR /&gt;the respective discrete links to the mentioned examples are:&lt;BR /&gt;&lt;A target="_blank" href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/dgesv.htm#top"&gt;http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/dgesv.htm#top&lt;/A&gt;&lt;BR /&gt;and for the version which is the one which applies here (row major) it is &lt;BR /&gt;&lt;A target="_blank" href="http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/lapacke_dgesv_row.c.htm"&gt;http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/lapacke_dgesv_row.c.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Please find below a corrected version of the C++ source which gives a result identical to the Fortran version.&lt;BR /&gt;The main differences are the usage of:&lt;BR /&gt;info = LAPACKE_dgesv(LAPACK_ROW_MAJOR, n, nrhs, *a, lda, ipiv, *b, ldb);&lt;BR /&gt;and a fix concerning the size of ldb which has to be identical to nrhs (i.e. NJ). (The size of a is [NI][NI] while the size of b is [NI][&lt;B&gt;NJ&lt;/B&gt;]!)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]#include "mkl.h"
#include "mkl_lapacke.h"
#include &lt;MATH.H&gt;
#include &lt;IOSTREAM&gt;
using namespace std;
#define NI 4 
#define NJ 3 

int main(int argc, char* argv[]) 
{ 
	double a[NI][NI]; 
	double b[NI][NJ]; 

	a[0][0] = 1; 
	a[0][1] = 1; 
	a[0][2] = 1; 
	a[0][3] = 1; 
	a[1][0] = 7.4895; 
	a[1][1] = 7.5292; 
	a[1][2] = 7.3905; 
	a[1][3] = 7.4141; 
	a[2][0] = 1.1759; 
	a[2][1] = 1.2956; 
	a[2][2] = 1.2342; 
	a[2][3] = 1.3149; 
	a[3][0] = 0.1496; 
	a[3][1] = 0.3214; 
	a[3][2] = 0.2887; 
	a[3][3] = 0.1598; 

	b[0][0] = 0; 
	b[0][1] = 0; 
	b[0][2] = 0; 
	b[1][0] = 1; 
	b[1][1] = 0; 
	b[1][2] = 0; 
	b[2][0] = 0; 
	b[2][1] = 1; 
	b[2][2] = 0; 
	b[3][0] = 0; 
	b[3][1] = 0; 
	b[3][2] = 1; 

	cout &amp;lt;&amp;lt; "A1 = n"; 
	for(int i = 0; i &amp;lt; NI; i++) { 
		for(int j = 0; j &amp;lt; NI; j++) { 
			cout &amp;lt;&amp;lt; a&lt;I&gt;&lt;J&gt; &amp;lt;&amp;lt; "t"; 
		} 
		cout &amp;lt;&amp;lt; "n"; 
	} 
	cout &amp;lt;&amp;lt; "n"; 

	MKL_INT ipiv[NI]; 
	for (int i = 0; i &amp;lt; NI; i++){ 
		ipiv&lt;I&gt; = 0; 
	} 

	cout &amp;lt;&amp;lt; "B1 = n"; 
	for(int i = 0; i &amp;lt; NI; i++) { 
		for(int j = 0; j &amp;lt; NJ; j++) { 
			cout &amp;lt;&amp;lt; b&lt;I&gt;&lt;J&gt; &amp;lt;&amp;lt; "t"; 
		} 
		cout &amp;lt;&amp;lt; "n"; 
	} 
	cout &amp;lt;&amp;lt; "n"; 
	MKL_INT n = NI;
	MKL_INT nrhs = NJ;
	MKL_INT lda = NI;
	MKL_INT ldb = NJ;
	MKL_INT info = -1;
	info = LAPACKE_dgesv(LAPACK_ROW_MAJOR, n, nrhs, *a, lda, ipiv, *b, ldb);

	cout &amp;lt;&amp;lt; "INFO = " &amp;lt;&amp;lt; info &amp;lt;&amp;lt; "n"; 

	cout &amp;lt;&amp;lt; "G = n"; 
	cout.setf(std::ios::scientific); 
	for(int i = 0; i &amp;lt; NI; i++) { 
		for(int j = 0; j &amp;lt; NJ; j++) { 
			cout &amp;lt;&amp;lt; b&lt;I&gt;&lt;J&gt; &amp;lt;&amp;lt; "t"; 
		} 
		cout &amp;lt;&amp;lt; "n"; 
	} 
	cout &amp;lt;&amp;lt; "n"; 

	return 0; 
} 
[/cpp]&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/IOSTREAM&gt;&lt;/MATH.H&gt;&lt;/PRE&gt;&lt;BR /&gt;Kind regards&lt;BR /&gt;Wolfram</description>
      <pubDate>Wed, 05 Jan 2011 15:33:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/problem-using-c-version-of-dgesv/m-p/830215#M5480</guid>
      <dc:creator>geowolf</dc:creator>
      <dc:date>2011-01-05T15:33:27Z</dc:date>
    </item>
  </channel>
</rss>

