<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252632</link>
    <title>MATLAB Central Newsreader - sparse matrix multiplication and cgs()</title>
    <description>Feed for thread: sparse matrix multiplication and cgs()</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 01 Jun 2009 15:19:26 -0400</pubDate>
      <title>sparse matrix multiplication and cgs()</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252632#653825</link>
      <author>GS</author>
      <description>Hello, &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;I solved Ax=b, A is large(of size 2e5), sparse(each row has no more than 26 nonzero), symmetric positive definite matrix. I did it in two ways, &lt;br&gt;
1) L=chol(A,'lower'); tic, x=L\(L'\b),toc;&lt;br&gt;
2) tic,[x,flag,resrel,iter]=cgs(A,b,[],n,[],[],x0),toc;&lt;br&gt;
&lt;br&gt;
L is dense, iter=6. So theoretical 2) should be must faster than 1). But 1), 2) ends up with the same time.&lt;br&gt;
Why?</description>
    </item>
    <item>
      <pubDate>Mon, 01 Jun 2009 15:36:01 -0400</pubDate>
      <title>Re: sparse matrix multiplication and cgs()</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252632#653831</link>
      <author>Bruno Luong</author>
      <description>GS &amp;lt;gshy2014@gamil.com&amp;gt; wrote in message &amp;lt;17247123.13121.1243869597327.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Hello, &lt;br&gt;
&amp;gt;    I solved Ax=b, A is large(of size 2e5), sparse(each row has no more than 26 nonzero), symmetric positive definite matrix. I did it in two ways, &lt;br&gt;
&amp;gt; 1) L=chol(A,'lower'); tic, x=L\(L'\b),toc;&lt;br&gt;
&amp;gt; 2) tic,[x,flag,resrel,iter]=cgs(A,b,[],n,[],[],x0),toc;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L is dense, iter=6. So theoretical 2) should be must faster than 1). &lt;br&gt;
&lt;br&gt;
Why not using PCG, which is design for spd matrix? Not sure about the &quot;theoretical&quot; claim above: CGS/PCG convergence depends on the condition number of A. If cond(A)=A it will converge in no time (1 iteration is enough in fact).&lt;br&gt;
&lt;br&gt;
Iterative methods are not always faster than direct method.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Tue, 02 Jun 2009 02:01:04 -0400</pubDate>
      <title>Re: sparse matrix multiplication and cgs()</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252632#653948</link>
      <author>Tim Davis</author>
      <description>GS &amp;lt;gshy2014@gamil.com&amp;gt; wrote in message &amp;lt;17247123.13121.1243869597327.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Hello, &lt;br&gt;
&amp;gt;    I solved Ax=b, A is large(of size 2e5), sparse(each row has no more than 26 nonzero), symmetric positive definite matrix. I did it in two ways, &lt;br&gt;
&amp;gt; 1) L=chol(A,'lower'); tic, x=L\(L'\b),toc;&lt;br&gt;
&amp;gt; 2) tic,[x,flag,resrel,iter]=cgs(A,b,[],n,[],[],x0),toc;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L is dense, iter=6. So theoretical 2) should be must faster than 1). But 1), 2) ends up with the same time.&lt;br&gt;
&amp;gt; Why?&lt;br&gt;
&lt;br&gt;
chol will be much faster if you allow it to permute the matrix (and L will not be dense).  Try:&lt;br&gt;
&lt;br&gt;
tic ; [L g q] = chol (A, 'lower') ; toc&lt;br&gt;
tic ; x = q * (L' \ (L \ (q' * b))) ; toc&lt;br&gt;
&lt;br&gt;
See also the FACTORIZE object, here: &lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/24119&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/24119&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
which does this for you.  You can speed the forward/backsolve even further by using cs_lsolve for the L\(...) part, and cs_ltsolve for the L'\(...) part. See CSparse on my web page at &lt;a href=&quot;http://www.cise.ufl.edu/research/sparse.&quot;&gt;http://www.cise.ufl.edu/research/sparse.&lt;/a&gt;  The L'\(...) solve in MATLAB forms the explicit L transpose, which is slow.  Alternatively, you could just compute LT = L' first, and then do the backslashes.&lt;br&gt;
&lt;br&gt;
x=A\b does all this without forming L transpose explicitly. &lt;br&gt;
&lt;br&gt;
THe other problem you have, which is more fundamental, is that your test is printing out the solution x (you have a comma instead of a semicolon).  That dominates the run time, so it's not surprising that both methods take the same amount of time.&lt;br&gt;
&lt;br&gt;
You can speed up chol even more by using a better ordering method that isn't in MATLAB (METIS).  CHOLMOD has an interface to it (in SuiteSparse, at the same web page).&lt;br&gt;
&lt;br&gt;
In any case, a problem of dimension 2e5 is probably small enough that a direct method will typically be faster ... at least if you allow it to do a fill-reducing ordering.</description>
    </item>
    <item>
      <pubDate>Tue, 02 Jun 2009 18:03:45 -0400</pubDate>
      <title>Re: sparse matrix multiplication and cgs()</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252632#654143</link>
      <author>Shiyuan Gu</author>
      <description>&amp;gt; Why not using PCG, which is design for spd matrix?&lt;br&gt;
pcg is slower than cgs. pcg() needs about 16 iterations.&lt;br&gt;
&lt;br&gt;
&amp;gt; Not sure about the &quot;theoretical&quot; claim above: &lt;br&gt;
I mean the floating point operation count. Since there are no more than 26 nozeros each row/column, we only need O(n) (where n=size(A,1)) additions/multiplications for each iteratios. since we only need no more than 10 iterations in total. The total number of addition/multiplications is O(n). But for L\y, we need 2n^2 additions/multiplications. &lt;br&gt;
&lt;br&gt;
&amp;gt;CGS/PCG convergence depends on the condition number of &amp;gt;A. If cond(A)=A it will converge in no time (1 &amp;gt;iteration is enough in fact).&lt;br&gt;
&lt;br&gt;
cond(A) is not too bad.(about 1e3). cond(A) will affect the convergence, but it turns out that the it only needs no more than 6 iterations.&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Iterative methods are not always faster than direct&lt;br&gt;
&amp;gt; method.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno</description>
    </item>
  </channel>
</rss>

