<?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 Using LAPACK_sgesv to solve a linear system with std::vector in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Using-LAPACK-sgesv-to-solve-a-linear-system-with-std-vector/m-p/1072178#M22333</link>
    <description>&lt;P&gt;I am trying to use the LAPACK_sgesv function from the MKL to solve a linear system, which is part of a much larger problem. Now, as an example, this produces the correct answer:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;int size = 4

float a[16] = {1, 1, 1 , 1, -2, -1, 1, 2, 4, 1, 1, 4, -8, -1, 1, 8}; // matrix A of Ax = B
float b[4] = { 0, 1, 0, 0 }; // vector B of Ax = B
int p[4] = { 0, 0, 0, 0 }; // array to store pivot indices


LAPACKE_sgesv(LAPACK_ROW_MAJOR, size, 1, a, size, p, b, 1);


for (auto&amp;amp; element : b)
	std::cout &amp;lt;&amp;lt; "\n" &amp;lt;&amp;lt; element;&lt;/PRE&gt;

&lt;P&gt;The output is correct, and this behaves without errors. However, the main problem I have is that this function does not seem to work nicely with std::vectors:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;int size = 4

std::vector&amp;lt;float&amp;gt; A = { 1, 1, 1, 1, -2, -1, 1, 2, 4, 1, 1, 4, -8, -1, 1, 8 };
std::vector&amp;lt;float&amp;gt; B = { 0, 1, 0, 0 };
std::vector&amp;lt;int&amp;gt; P = { 0, 0, 0, 0 };

LAPACKE_sgesv(LAPACK_ROW_MAJOR, size, 1, &amp;amp;A[0], size, &amp;amp;P[0], &amp;amp;B[0], 1);

for (auto&amp;amp; element : b)
	std::cout &amp;lt;&amp;lt; "\n" &amp;lt;&amp;lt; element;&lt;/PRE&gt;

&lt;P&gt;The output I get is simply 0, 1, 0, 0, which is the unmodified output vector which the answer is suppose to be written to. The LAPACK returns zero, suggesting it executed successfully... Any ideas as to how to get it to work with vector? In my real use of this function in a larger calculation, I need to use resizeable contiguous containers, not arrays.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Nov 2016 08:44:07 GMT</pubDate>
    <dc:creator>Jamal_S_1</dc:creator>
    <dc:date>2016-11-02T08:44:07Z</dc:date>
    <item>
      <title>Using LAPACK_sgesv to solve a linear system with std::vector</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Using-LAPACK-sgesv-to-solve-a-linear-system-with-std-vector/m-p/1072178#M22333</link>
      <description>&lt;P&gt;I am trying to use the LAPACK_sgesv function from the MKL to solve a linear system, which is part of a much larger problem. Now, as an example, this produces the correct answer:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;int size = 4

float a[16] = {1, 1, 1 , 1, -2, -1, 1, 2, 4, 1, 1, 4, -8, -1, 1, 8}; // matrix A of Ax = B
float b[4] = { 0, 1, 0, 0 }; // vector B of Ax = B
int p[4] = { 0, 0, 0, 0 }; // array to store pivot indices


LAPACKE_sgesv(LAPACK_ROW_MAJOR, size, 1, a, size, p, b, 1);


for (auto&amp;amp; element : b)
	std::cout &amp;lt;&amp;lt; "\n" &amp;lt;&amp;lt; element;&lt;/PRE&gt;

&lt;P&gt;The output is correct, and this behaves without errors. However, the main problem I have is that this function does not seem to work nicely with std::vectors:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;int size = 4

std::vector&amp;lt;float&amp;gt; A = { 1, 1, 1, 1, -2, -1, 1, 2, 4, 1, 1, 4, -8, -1, 1, 8 };
std::vector&amp;lt;float&amp;gt; B = { 0, 1, 0, 0 };
std::vector&amp;lt;int&amp;gt; P = { 0, 0, 0, 0 };

LAPACKE_sgesv(LAPACK_ROW_MAJOR, size, 1, &amp;amp;A[0], size, &amp;amp;P[0], &amp;amp;B[0], 1);

for (auto&amp;amp; element : b)
	std::cout &amp;lt;&amp;lt; "\n" &amp;lt;&amp;lt; element;&lt;/PRE&gt;

&lt;P&gt;The output I get is simply 0, 1, 0, 0, which is the unmodified output vector which the answer is suppose to be written to. The LAPACK returns zero, suggesting it executed successfully... Any ideas as to how to get it to work with vector? In my real use of this function in a larger calculation, I need to use resizeable contiguous containers, not arrays.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 08:44:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Using-LAPACK-sgesv-to-solve-a-linear-system-with-std-vector/m-p/1072178#M22333</guid>
      <dc:creator>Jamal_S_1</dc:creator>
      <dc:date>2016-11-02T08:44:07Z</dc:date>
    </item>
    <item>
      <title>Hi Jamal,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Using-LAPACK-sgesv-to-solve-a-linear-system-with-std-vector/m-p/1072179#M22334</link>
      <description>&lt;P&gt;Hi Jamal,&lt;/P&gt;

&lt;P&gt;I guess, there is a little typo in the std:: code&amp;nbsp;&lt;/P&gt;

&lt;P&gt;for (auto&amp;amp; element : b) &amp;nbsp;----&amp;gt; B&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;std::cout &amp;lt;&amp;lt; "\n" &amp;lt;&amp;lt; element;&lt;BR /&gt;
	Then you will get the same result as the array code.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Anyway, it is good question, so i add one more comment: &amp;nbsp;the key question here is whether the memory of &amp;nbsp;std:vector can be accessed continuously by &amp;nbsp;&amp;amp;A[0], &amp;amp;A[0]+1 ...... &amp;nbsp;. &amp;nbsp;If yes, it is not problem to call MKL function with &amp;nbsp;LAPACKE_sgesv( &amp;amp;A[0], , &amp;amp;P[0], &amp;amp;B[0]); Otherwise, no.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;So you need to assure this point. &amp;nbsp;From the definition of std:vector, resizeable contiguous containers, it should be yes, right?&lt;/P&gt;

&lt;P&gt;Best Regards,&lt;/P&gt;

&lt;P&gt;Ying&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper" image-alt="L_FA42.tmp_.PNG"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/9197iCC3E5B0560E7BD71/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="L_FA42.tmp_.PNG" alt="L_FA42.tmp_.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 08:15:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Using-LAPACK-sgesv-to-solve-a-linear-system-with-std-vector/m-p/1072179#M22334</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2016-11-03T08:15:19Z</dc:date>
    </item>
  </channel>
</rss>

