Hi, I traced the program on the level of KSPSolve_CG,  and I don&#39;t see the MatNullSpace is used. Where is MatNullSpace used? Can KSP CG automatically handle the null space provided by MatNullSpace? Or I need to change to some other solver? The matrix is semi-positive-definite with only one zero eigenvalue. The zero eigenvector is obtained by an eigensolver. Any suggestion? Thanks.<div>
<br></div><div> <div>Shiyuan  <div><br><div class="gmail_quote">On Fri, Dec 2, 2011 at 11:17 PM, Barry Smith <span dir="ltr">&lt;<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Dec 2, 2011, at 10:57 PM, Shiyuan wrote:<br>
<br>
&gt; I notice that when the vector indicating the nullspace is not very accurate (norm(A*phi) very small but not zero), KSP (CG) will return KSP_INDEFINITE_PC. When b is very close to zero in AX=b, KSP (CG) has the same error. Is it controlled by some tolerance? How can I set the tolerance?<br>

<br>
</div>   No it is not controlled by some tolerance, it cannot be controlled by some tolerance because the indication of indefiniteness is determined by<br>
<br>
     } else if ((i &gt; 0) &amp;&amp; (beta*betaold &lt; 0.0)) {<br>
       ksp-&gt;reason = KSP_DIVERGED_INDEFINITE_PC;<br>
       ierr = PetscInfo(ksp,&quot;diverging due to indefinite preconditioner\n&quot;);CHKERRQ(ierr);<br>
       break;<br>
<br>
as soon as beta*betaold is negative the entire CG algorithm breaks down and there is no way to recover.<br>
<span class="HOEnZb"><font color="#888888"><br>
   Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
&gt; Thanks.<br>
&gt;<br>
&gt; Shiyuan<br>
&gt;<br>
&gt; On Wed, Nov 23, 2011 at 5:00 PM, Barry Smith &lt;<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt; wrote:<br>
&gt;<br>
&gt; On Nov 23, 2011, at 1:31 PM, Shiyuan wrote:<br>
&gt;<br>
&gt; &gt; I&#39;ve check it in Matlab. the matrix A is symmetric and has no negative eigenvalues( only a zero eigen value). I&#39;ve also checked that the nullspace is correct(  norm(A*phi)&lt;1e-11);<br>
&gt;<br>
&gt;   Hmm. You can run with -ksp_view_binary and email to <a href="mailto:petsc-maint@mcs.anl.gov">petsc-maint@mcs.anl.gov</a> the resulting file called binaryoutput.<br>
&gt;<br>
&gt;   Barry<br>
&gt;<br>
&gt;<br>
&gt; &gt; Thanks.<br>
&gt; &gt;<br>
&gt; &gt; On Wed, Nov 23, 2011 at 1:26 PM, Barry Smith &lt;<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt;   Print out the matrix for a small grid then check in Matlab that it is symmetric and has no negative eigenvalues.<br>
&gt; &gt;<br>
&gt; &gt;   Barry<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; On Nov 23, 2011, at 9:50 AM, Shiyuan wrote:<br>
&gt; &gt;<br>
&gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt;     I want to solve a singular system with a known nullspace. However, I the KSP solve diverges with KSP_INDEFINTE_PC even if I disable the preconditioning by PCNONE.<br>
&gt; &gt; &gt; this is how I setup the system. What did I do wrong? Any possible causes? Thanks.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;    ierr=MatNullSpaceCreate(PETSC_COMM_SELF,PETSC_FALSE,1,&amp;phi,&amp;nsp);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPCreate(PETSC_COMM_SELF,&amp;ksp);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPSetNullSpace(ksp,nsp);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPSetType(ksp,KSPCG);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPGetPC(ksp,&amp;prec);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=PCSetType(prec,PCNONE);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPSetTolerances(ksp,1e-5,1e-20,1e5,10000);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPSetFromOptions(ksp);CHKERRV(ierr);<br>
&gt; &gt; &gt;   ierr=KSPSetUp(ksp);CHKERRV(ierr);<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Shiyuan<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
<br>
</div></div></blockquote></div><br></div></div></div>