<?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 get LAPACKE_dgbtrf to return a meaningful result for row_major format. in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303124#M31840</link>
    <description>&lt;P&gt;I've tried many variations, but I can't seem to figure out how to format a simple banded matrix in row_major format.&amp;nbsp; The following code uses a complete 4x4 matrix and finds the LU decomposition, and then solves a simple linear equation.&lt;BR /&gt;&lt;BR /&gt;I'd like to do the same with the banded matrix interface dgbtrf, but I only get nonsense as output.&amp;nbsp; The documentation for row_major matrices is less complete than for column_major and also contains obvious errors.&lt;BR /&gt;&lt;BR /&gt;So can somebody tell me what the matrix dmatBanded should look like, and what the right parameters are for LAPACKE_dgbtrf?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have included test code below and its output.&amp;nbsp; First I use dgetrf on matrix dmat.&amp;nbsp; Then I try to use dgbtrf on matrix dmatBanded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;PS - Running C++ 2018.2.185 on Windows 7.&amp;nbsp; Visual Studio 2015.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void LinearAlgebra::Test01()
{
	using std::cout;
	using std::endl;

	double dmat[16] =
	{
		2.00, -0.50,  0.00,  0.00,
	   -0.01,  1.30, -0.20,  0.00,
		0.00, -0.05, -0.40,  3.00,
		0.00,  0.00,  0.30,  1.50
	};
	lapack_int pivots[4];
	PrintMatrix(dmat, 4, 4, "dmat");
	lapack_int info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, 4, 4, dmat, 4, pivots);
	PrintMatrix(dmat, 4, 4, "dmat LU");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgetrs(LAPACK_ROW_MAJOR, 'N', 4, 1, dmat, 4, pivots, bvec, 1);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";

	double dmatBanded[16] =
	{
		0.00,  2.00, -0.50,  0.00, 
	   -0.01,  1.30, -0.20,  0.00,
	   -0.05, -0.40,  3.00,  0.00,
		0.30,  1.50,  0.00,  0.00
	};
	PrintMatrix(dmatBanded, 4, 4, "dmatBanded");
	int rows = 4;
	int cols = 4;
	int kl = 1;
	int ku = 1;
	int ldab = 4;
	info = LAPACKE_dgbtrf(LAPACK_ROW_MAJOR, rows, cols, kl, ku, dmatBanded, ldab, pivots);
	PrintMatrix(dmatBanded, 4, 4, "dmatBanded LU result");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec2[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgbtrs(LAPACK_ROW_MAJOR, 'N', rows, kl, ku, 1, dmatBanded, ldab, pivots, bvec2, 1);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec2, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;dmat
   2.000000  -0.500000   0.000000   0.000000
  -0.010000   1.300000  -0.200000   0.000000
   0.000000  -0.050000  -0.400000   3.000000
   0.000000   0.000000   0.300000   1.500000

dmat LU
   2.000000  -0.500000   0.000000   0.000000
  -0.005000   1.297500  -0.200000   0.000000
   0.000000  -0.038536  -0.407707   3.000000
   0.000000   0.000000  -0.735822   3.707467

info=0 pivots=1,2,3,4
info=0
solution
   1.074570   2.298279   4.885086   1.689649

-----------------

dmatBanded
   0.000000   2.000000  -0.500000   0.000000
  -0.010000   1.300000  -0.200000   0.000000
  -0.050000  -0.400000   3.000000   0.000000
   0.300000   1.500000   0.000000   0.000000

dmatBanded LU result
   0.000000   2.000000  -0.200000   0.000000
  -0.010000  -0.400000   3.000000   0.000000
   0.300000   1.500000  -2.500000   0.000000
  -0.166667   0.822222  -0.000000   0.000000

info=4 pivots=2,3,3,4
info=0
solution
  -nan(ind)  -nan(ind)  -nan(ind)        inf

-----------------&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, here's PrintMatrix if you like.&amp;nbsp; It is not interesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void LinearAlgebra::PrintMatrix(double *mat, int n, int m, char *title)
{
	using std::cout;
	using std::endl;

	cout &amp;lt;&amp;lt; title &amp;lt;&amp;lt; endl;
	char buf[128];
	for (int i = 0; i &amp;lt; n; i++)
	{
		for (int j = 0; j &amp;lt; m; j++)
		{
			sprintf_s(buf, 128, " %10.6f", mat[i*m+j]);
			cout &amp;lt;&amp;lt; buf;
		}
		cout &amp;lt;&amp;lt; endl;
	}
	cout &amp;lt;&amp;lt; endl;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2021 23:52:39 GMT</pubDate>
    <dc:creator>chuckwh</dc:creator>
    <dc:date>2021-08-02T23:52:39Z</dc:date>
    <item>
      <title>Cannot get LAPACKE_dgbtrf to return a meaningful result for row_major format.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303124#M31840</link>
      <description>&lt;P&gt;I've tried many variations, but I can't seem to figure out how to format a simple banded matrix in row_major format.&amp;nbsp; The following code uses a complete 4x4 matrix and finds the LU decomposition, and then solves a simple linear equation.&lt;BR /&gt;&lt;BR /&gt;I'd like to do the same with the banded matrix interface dgbtrf, but I only get nonsense as output.&amp;nbsp; The documentation for row_major matrices is less complete than for column_major and also contains obvious errors.&lt;BR /&gt;&lt;BR /&gt;So can somebody tell me what the matrix dmatBanded should look like, and what the right parameters are for LAPACKE_dgbtrf?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have included test code below and its output.&amp;nbsp; First I use dgetrf on matrix dmat.&amp;nbsp; Then I try to use dgbtrf on matrix dmatBanded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;PS - Running C++ 2018.2.185 on Windows 7.&amp;nbsp; Visual Studio 2015.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void LinearAlgebra::Test01()
{
	using std::cout;
	using std::endl;

	double dmat[16] =
	{
		2.00, -0.50,  0.00,  0.00,
	   -0.01,  1.30, -0.20,  0.00,
		0.00, -0.05, -0.40,  3.00,
		0.00,  0.00,  0.30,  1.50
	};
	lapack_int pivots[4];
	PrintMatrix(dmat, 4, 4, "dmat");
	lapack_int info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, 4, 4, dmat, 4, pivots);
	PrintMatrix(dmat, 4, 4, "dmat LU");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgetrs(LAPACK_ROW_MAJOR, 'N', 4, 1, dmat, 4, pivots, bvec, 1);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";

	double dmatBanded[16] =
	{
		0.00,  2.00, -0.50,  0.00, 
	   -0.01,  1.30, -0.20,  0.00,
	   -0.05, -0.40,  3.00,  0.00,
		0.30,  1.50,  0.00,  0.00
	};
	PrintMatrix(dmatBanded, 4, 4, "dmatBanded");
	int rows = 4;
	int cols = 4;
	int kl = 1;
	int ku = 1;
	int ldab = 4;
	info = LAPACKE_dgbtrf(LAPACK_ROW_MAJOR, rows, cols, kl, ku, dmatBanded, ldab, pivots);
	PrintMatrix(dmatBanded, 4, 4, "dmatBanded LU result");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec2[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgbtrs(LAPACK_ROW_MAJOR, 'N', rows, kl, ku, 1, dmatBanded, ldab, pivots, bvec2, 1);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec2, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;dmat
   2.000000  -0.500000   0.000000   0.000000
  -0.010000   1.300000  -0.200000   0.000000
   0.000000  -0.050000  -0.400000   3.000000
   0.000000   0.000000   0.300000   1.500000

dmat LU
   2.000000  -0.500000   0.000000   0.000000
  -0.005000   1.297500  -0.200000   0.000000
   0.000000  -0.038536  -0.407707   3.000000
   0.000000   0.000000  -0.735822   3.707467

info=0 pivots=1,2,3,4
info=0
solution
   1.074570   2.298279   4.885086   1.689649

-----------------

dmatBanded
   0.000000   2.000000  -0.500000   0.000000
  -0.010000   1.300000  -0.200000   0.000000
  -0.050000  -0.400000   3.000000   0.000000
   0.300000   1.500000   0.000000   0.000000

dmatBanded LU result
   0.000000   2.000000  -0.200000   0.000000
  -0.010000  -0.400000   3.000000   0.000000
   0.300000   1.500000  -2.500000   0.000000
  -0.166667   0.822222  -0.000000   0.000000

info=4 pivots=2,3,3,4
info=0
solution
  -nan(ind)  -nan(ind)  -nan(ind)        inf

-----------------&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, here's PrintMatrix if you like.&amp;nbsp; It is not interesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void LinearAlgebra::PrintMatrix(double *mat, int n, int m, char *title)
{
	using std::cout;
	using std::endl;

	cout &amp;lt;&amp;lt; title &amp;lt;&amp;lt; endl;
	char buf[128];
	for (int i = 0; i &amp;lt; n; i++)
	{
		for (int j = 0; j &amp;lt; m; j++)
		{
			sprintf_s(buf, 128, " %10.6f", mat[i*m+j]);
			cout &amp;lt;&amp;lt; buf;
		}
		cout &amp;lt;&amp;lt; endl;
	}
	cout &amp;lt;&amp;lt; endl;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 23:52:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303124#M31840</guid>
      <dc:creator>chuckwh</dc:creator>
      <dc:date>2021-08-02T23:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get LAPACKE_dgbtrf to return a meaningful result for row_major format.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303300#M31846</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for posting your query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&lt;I&gt;The documentation for row_major matrices is less complete than for column_major and also contains obvious errors.&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide us links where the documentation contains errors and what do you think should be added to the row_major matrices?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&lt;I&gt;So can somebody tell me what the matrix dmatBanded should look like, and what the right parameters are for LAPACKE_dgbtrf?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please visit this link for more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link for band matrix: &lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/lapack-routines/matrix-storage-schemes-for-lapack-routines.html#matrix-storage-schemes-for-lapack-routines_BAND_STORAGE" target="_blank" rel="noopener"&gt;https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/lapack-routines/matrix-storage-schemes-for-lapack-routines.html#matrix-storage-schemes-for-lapack-routines_BAND_STORAGE&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link for dgbtrf: &lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-factorization-lapack-computational-routines/gbtrf.html#gbtrf" target="_blank" rel="noopener"&gt;https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/lapack-routines/lapack-linear-equation-routines/lapack-linear-equation-computational-routines/matrix-factorization-lapack-computational-routines/gbtrf.html#gbtrf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Along with these details can you please provide the MKL Version used?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let us know if you have any queries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Rajesh.&lt;/P&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 14:39:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303300#M31846</guid>
      <dc:creator>MRajesh_intel</dc:creator>
      <dc:date>2021-08-03T14:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get LAPACKE_dgbtrf to return a meaningful result for row_major format.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303333#M31847</link>
      <description>&lt;P&gt;Here is the first documentation bug that comes to mind.&amp;nbsp; It's from the "Link for band matrix" that you provided.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RowMajorDoc.PNG" style="width: 999px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18529i6446C24C23B92A31/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="RowMajorDoc.PNG" alt="RowMajorDoc.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Of course, the row major layout calculation is silly.&amp;nbsp; It should not use &lt;STRONG&gt;(kl+ku+1)&lt;/STRONG&gt;, it should use &lt;STRONG&gt;ldab&lt;/STRONG&gt;.&amp;nbsp; In the case of dgbtrf, ldab must be greater than or equal to (2*kl+ku+1), so that is troublesome.&lt;BR /&gt;I might also mention that both the column and row major discussions that precede this always assume i and j are 1-based, as in fortran.&amp;nbsp; But the indices calculated with these two formulae for the location in a[k(i,j)] are zero-based.&amp;nbsp; This is confusing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have referred to the documentation you reference dozens of times, and it is what led me to the code that I wrote.&amp;nbsp; It's all about this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chuckwh_1-1628004286767.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18531i38C005E267E50E34/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="chuckwh_1-1628004286767.png" alt="chuckwh_1-1628004286767.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Is this the correct order for the entries in a row_major 4x4 banded matrix?&amp;nbsp; As I read and interpret the documentation, it is correct.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using the MKL that came with C++ 2018.2.185, so it seems to have the same version number.&amp;nbsp; I am static linking to the MKL, and using 32 bit integers.&amp;nbsp; You can see in my code that the library works, until I get to the banded matrix call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Chuck&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 15:32:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303333#M31847</guid>
      <dc:creator>chuckwh</dc:creator>
      <dc:date>2021-08-03T15:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get LAPACKE_dgbtrf to return a meaningful result for row_major format.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303396#M31849</link>
      <description>&lt;P&gt;OK, I am going to have to solve this myself.&lt;BR /&gt;Summary: The Intel MKL documentation relating to banded matrix storage in row major format is badly misleading.&amp;nbsp; Which is to say it is very very wrong.&lt;BR /&gt;&lt;BR /&gt;Let's start with this link:&amp;nbsp;&lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/lapack-routines/matrix-storage-schemes-for-lapack-routines.html" target="_self"&gt;(intel documentation for banded matrix storage)&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For row major storage, like I use in C++, they say the banded version of a stored matrix should look like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chuckwh_0-1628014948803.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18536i89EC002448704E9F/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="chuckwh_0-1628014948803.png" alt="chuckwh_0-1628014948803.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Some things to note: &lt;BR /&gt;1) The main diagonal of the original matrix a[1,1], a[2,2], etc, appears as a column in the banded version.&lt;BR /&gt;2) The first sub-diagonal, a[2,1], a[3,2], etc, is a column left of the main diagonal. Also it is displaced downward by one row compared to the main diagonal.&lt;BR /&gt;3) The first super-diagonal, a[1,2], a[2,3], etc, appears in a column to the right of the main diagonal and is even with the top of the main diagonal.&lt;BR /&gt;This is pretty clear from the picture, right?&lt;BR /&gt;Then for dgbtrf I know that I need to reserve another super diagonal for the output.&amp;nbsp; So that puts another column on the right.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Let's apply this knowledge.&lt;BR /&gt;This is my full matrix, as posted yesterday:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chuckwh_1-1628015305211.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18537i987F9E21C73D1F7D/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="chuckwh_1-1628015305211.png" alt="chuckwh_1-1628015305211.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So following the three points above, I construct my version of the banded matrix:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chuckwh_2-1628015392273.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18538i34957D9B48ECBEF6/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="chuckwh_2-1628015392273.png" alt="chuckwh_2-1628015392273.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As in the documentation: "Diagonals of A become columns of AB".&lt;BR /&gt;Consider also the formula given a little below in the same document:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chuckwh_3-1628015526369.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18539i4B99B20666647ED5/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="chuckwh_3-1628015526369.png" alt="chuckwh_3-1628015526369.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Look at the row major layout formula and consider where diagonal elements go.&amp;nbsp; Note that i=j, so that the next sequential diagonal element should be located according to kl+(i-1)(kl+ku+1).&amp;nbsp; In particular, it is located (kl+ku+1) away in the flattened array. (And that term is silly in itself. ldab is more likely.)&lt;/P&gt;
&lt;P&gt;I have followed the instructions carefully, and arrived where I did.&amp;nbsp; By searching the internet, I have found that every couple of years a confused person posts this question, and they have tried an array definition just like mine, and they have failed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So:&amp;nbsp;&lt;U&gt;All of the above documentation is completely wrong&lt;/U&gt;.&lt;/P&gt;
&lt;P&gt;Here is the matrix that actually works for LPACK_ROW_MAJOR format:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chuckwh_4-1628015895981.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/18540i4A754706FF263A4E/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="chuckwh_4-1628015895981.png" alt="chuckwh_4-1628015895981.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note that the main diagonal is a row, not a column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that sequential diagonal elements are stored sequentially in memory, not separated by ldab.&lt;/P&gt;
&lt;P&gt;Note that the sub-diagonal is aligned with the main diagonal, not offset.&amp;nbsp; And vice versa for the super-diagonal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a code sample in which it works:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void LinearAlgebra::Test01()
{
	using std::cout;
	using std::endl;

	double dmat[16] =
	{
	    2.00, -0.50,  0.00,  0.00, 
	   -0.01,  1.30, -0.20,  0.00,
	    0.00, -0.05, -0.40,  3.00,
	    0.00,  0.00,  0.30,  1.50
	};
	lapack_int pivots[4];
	PrintMatrix(dmat, 4, 4, "dmat");
	lapack_int info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, 4, 4, dmat, 4, pivots);
	PrintMatrix(dmat, 4, 4, "dmat LU");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgetrs(LAPACK_ROW_MAJOR, 'N', 4, 1, dmat, 4, pivots, bvec, 1);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";

	double dmatBanded[16] =
	{
	    0.00,  0.00,  0.00, 0.00,
	    0.00, -0.50, -0.20, 3.00,
	    2.00,  1.30, -0.40, 1.50,
	   -0.01, -0.05,  0.30, 0.00
	};
	PrintMatrix(dmatBanded, 4, 4, "dmatBanded");
	int rows = 4;
	int cols = 4;
	int kl = 1;
	int ku = 1;
	int ldab = 4;
	info = LAPACKE_dgbtrf(LAPACK_ROW_MAJOR, rows, cols, kl, ku, dmatBanded, ldab, pivots);
	PrintMatrix(dmatBanded, 4, 4, "dmatBanded LU result");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec2[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgbtrs(LAPACK_ROW_MAJOR, 'N', rows, kl, ku, 1, dmatBanded, ldab, pivots, bvec2, 1);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec2, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";

	double dmatBandedCol[16] =
	{
		0.00,  0.00,  2.00, -0.01,
		0.00, -0.50,  1.30, -0.05,
		0.00, -0.20, -0.40,  0.30,
	    0.00,  3.00,  1.50,  0.00
	};
	PrintMatrix(dmatBandedCol, 4, 4, "dmatBanded column major");
	rows = 4;
	cols = 4;
	kl = 1;
	ku = 1;
	ldab = 4;
	info = LAPACKE_dgbtrf(LAPACK_COL_MAJOR, rows, cols, kl, ku, dmatBandedCol, ldab, pivots);
	PrintMatrix(dmatBandedCol, 4, 4, "dmatBandedCol LU result");
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; " pivots=" &amp;lt;&amp;lt; pivots[0] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[1] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[2] &amp;lt;&amp;lt; "," &amp;lt;&amp;lt; pivots[3] &amp;lt;&amp;lt; endl;
	double bvec3[4] = { 1.0, 2.0, 3.0, 4.0 };
	info = LAPACKE_dgbtrs(LAPACK_COL_MAJOR, 'N', rows, kl, ku, 1, dmatBandedCol, ldab, pivots, bvec3, 4);
	cout &amp;lt;&amp;lt; "info=" &amp;lt;&amp;lt; info &amp;lt;&amp;lt; endl;
	PrintMatrix(bvec3, 1, 4, "solution");
	cout &amp;lt;&amp;lt; "-----------------\n\n";
}
&lt;/LI-CODE&gt;
&lt;P&gt;Here is the output of that code:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;dmat
   2.000000  -0.500000   0.000000   0.000000
  -0.010000   1.300000  -0.200000   0.000000
   0.000000  -0.050000  -0.400000   3.000000
   0.000000   0.000000   0.300000   1.500000

dmat LU
   2.000000  -0.500000   0.000000   0.000000
  -0.005000   1.297500  -0.200000   0.000000
   0.000000  -0.038536  -0.407707   3.000000
   0.000000   0.000000  -0.735822   3.707467

info=0 pivots=1,2,3,4
info=0
solution
   1.074570   2.298279   4.885086   1.689649

-----------------

dmatBanded
   0.000000   0.000000   0.000000   0.000000
   0.000000  -0.500000  -0.200000   3.000000
   2.000000   1.300000  -0.400000   1.500000
  -0.010000  -0.050000   0.300000   0.000000

dmatBanded LU result
   0.000000   0.000000   0.000000   0.000000
   0.000000  -0.500000  -0.200000   3.000000
   2.000000   1.297500  -0.407707   3.707467
  -0.005000  -0.038536  -0.735822   0.000000

info=0 pivots=1,2,3,4
info=0
solution
   1.074570   2.298279   4.885086   1.689649

-----------------

dmatBanded column major
   0.000000   0.000000   2.000000  -0.010000
   0.000000  -0.500000   1.300000  -0.050000
   0.000000  -0.200000  -0.400000   0.300000
   0.000000   3.000000   1.500000   0.000000

dmatBandedCol LU result
   0.000000   0.000000   2.000000  -0.005000
   0.000000  -0.500000   1.297500  -0.038536
   0.000000  -0.200000  -0.407707  -0.735822
   0.000000   3.000000   3.707467   0.000000

info=0 pivots=1,2,3,4
info=0
solution
   1.074570   2.298279   4.885086   1.689649

-----------------&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that there are no code samples on the net for using LAPACK_ROW_MAJOR banded matrices from C or C++ because people struggle with it for a while and then give up.&amp;nbsp; I hope this code sample gets found by the next person.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Chuck&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 19:00:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1303396#M31849</guid>
      <dc:creator>chuckwh</dc:creator>
      <dc:date>2021-08-03T19:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get LAPACKE_dgbtrf to return a meaningful result for row_major format.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1672584#M36981</link>
      <description>&lt;P&gt;Thanks chuckhw for sharing your hard work.&lt;/P&gt;&lt;P&gt;I’d arrived at the same matrices as yours from their documentation. The zeros in the wrong places were making gbtrf bomb out early. I was thinking along the lines of the matrices were in the wrong format (row/col major swapped or something) but never would have arrived at your correct solution.&lt;/P&gt;&lt;P&gt;Would be interesting to know where you got your additional info from, as I found absolutely nothing on the web.&lt;/P&gt;&lt;P&gt;It also blows my mind that Intel don’t update their docs, which is a shame.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2025 20:01:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-get-LAPACKE-dgbtrf-to-return-a-meaningful-result-for-row/m-p/1672584#M36981</guid>
      <dc:creator>dicksters1</dc:creator>
      <dc:date>2025-03-05T20:01:41Z</dc:date>
    </item>
  </channel>
</rss>

