Great, thank you.<br><br>Adding this <br><br>ierr = KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);<br> ierr = KSPSetType(ksp,KSPLSQR);//CHKERRQ(ierr);<br> ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);<br>
ierr = PCSetType(pc,PCNONE);CHKERRQ(ierr);<br><br>solved the problem<br><br><div class="gmail_quote">On Wed, May 23, 2012 at 6:29 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
You are trying the default preconditioner ILU(0) which requires a square matrix. Run with -pc_type none or see the manual page<br>
<br>
KSPLSQR - This implements LSQR<br>
<br>
Options Database Keys:<br>
+ -ksp_lsqr_set_standard_error - Set Standard Error Estimates of Solution see KSPLSQRSetStandardErrorVec()<br>
. -ksp_lsqr_monitor - Monitor residual norm and norm of residual of normal equations<br>
- see KSPSolve()<br>
<br>
Level: beginner<br>
<br>
Notes:<br>
This varient, when applied with no preconditioning is identical to the original algorithm in exact arithematic; however, in practice, with no preconditioning<br>
due to inexact arithematic, it can converge differently. Hence when no preconditioner is used (PCType PCNONE) it automatically reverts to the original algorithm.<br>
<br>
With the PETSc built-in preconditioners, such as ICC, one should call KSPSetOperators(ksp,A,A'*A,...) since the preconditioner needs to work<br>
for the normal equations A'*A.<br>
<br>
Supports only left preconditioning.<br>
<br>
References:The original unpreconditioned algorithm can be found in Paige and Saunders, ACM Transactions on Mathematical Software, Vol 8, pp 43-71, 1982.<br>
In exact arithmetic the LSQR method (with no preconditioning) is identical to the KSPCG algorithm applied to the normal equations.<br>
The preconditioned varient was implemented by Bas van't Hof and is essentially a left preconditioning for the Normal Equations. It appears the implementation with preconditioner<br>
track the true norm of the residual and uses that in the convergence test.<br>
<br>
Developer Notes: How is this related to the KSPCGNE implementation? One difference is that KSPCGNE applies<br>
the preconditioner transpose times the preconditioner, so one does not need to pass A'*A as the third argument to KSPSetOperators().<br>
<br>
<br>
For least squares problems without a zero to A*x = b, there are additional convergence tests for the residual of the normal equations, A'*(b - Ax), see KSPLSQRDefaultConverged()<br>
<br>
.seealso: KSPCreate(), KSPSetType(), KSPType (for list of available types), KSP, KSPLSQRDefaultConverged()<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On May 23, 2012, at 4:58 PM, Ildar Rakhmanov wrote:<br>
<br>
> Here is full message:<br>
><br>
> Matrix A after construction<br>
> row 0: (0, 1) (1, 0)<br>
> row 1: (0, 0) (1, 1)<br>
> row 2: (0, 1) (1, 1)<br>
> u<br>
> 1<br>
> 1<br>
> b<br>
> 0<br>
> 0<br>
> 0<br>
> b<br>
> 1<br>
> 1<br>
> 2<br>
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------<br>
> [0]PETSC ERROR: Invalid argument!<br>
> [0]PETSC ERROR: Must be square matrix, rows 3 columns 2!<br>
> [0]PETSC ERROR: ------------------------------------------------------------------------<br>
> [0]PETSC ERROR: Petsc Release Version 3.1.0, Patch 8, Thu Mar 17 13:37:48 CDT 2011<br>
> [0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
> [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
> [0]PETSC ERROR: See docs/index.html for manual pages.<br>
> [0]PETSC ERROR: ------------------------------------------------------------------------<br>
> [0]PETSC ERROR: ./lsqr on a linux-gnu named ildar by ildar Wed May 23 17:13:44 2012<br>
> [0]PETSC ERROR: Libraries linked from /home/ildar/pbsm/lib<br>
> [0]PETSC ERROR: Configure run at Sat Mar 3 12:01:22 2012<br>
> [0]PETSC ERROR: Configure options --prefix=/home/ildar/pbsm --download-hypre=1 --download-spooles=1 --download-plapack=1 --download-spai=1 --download-blacs=1 --download-triangle=1 --download-f-blas-lapack=1 --download-umfpack=1 --download-sowing=1 --download-c2html=1 --download-superlu_dist=1 --download-parmetis=1 --download-scalapack=1 --download-superlu=1 --download-mumps=1<br>
> [0]PETSC ERROR: ------------------------------------------------------------------------<br>
> [0]PETSC ERROR: MatGetOrdering() line 223 in src/mat/order/sorder.c<br>
> [0]PETSC ERROR: PCSetUp_ILU() line 194 in src/ksp/pc/impls/factor/ilu/ilu.c<br>
> [0]PETSC ERROR: PCSetUp() line 795 in src/ksp/pc/interface/precon.c<br>
> [0]PETSC ERROR: KSPSetUp() line 237 in src/ksp/ksp/interface/itfunc.c<br>
> [0]PETSC ERROR: KSPSolve() line 353 in src/ksp/ksp/interface/itfunc.c<br>
> [0]PETSC ERROR: main() line 109 in "unknowndirectory/"lsqr.c<br>
> application called MPI_Abort(MPI_COMM_WORLD, 62) - process 0<br>
><br>
><br>
><br>
><br>
> On Wed, May 23, 2012 at 5:29 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> You cut and threw away the most important part of the error message. Where is the stack trace? Are we to guess where the error message was triggered? Please send the entire error message.<br>
><br>
> Barry<br>
><br>
> On May 23, 2012, at 4:15 PM, Ildar Rakhmanov wrote:<br>
><br>
> > Hi,<br>
> > I seems I am missing something. I want to use KSPLSQR.<br>
> > I set up lsqr.c (see attachment)<br>
> > it uses 3x2 matrix.<br>
> ><br>
> > The results is<br>
> ><br>
> > ildar@ildar:~/lsqr> ./lsqr<br>
> > Matrix A after construction<br>
> > row 0: (0, 1) (1, 0)<br>
> > row 1: (0, 0) (1, 1)<br>
> > row 2: (0, 1) (1, 1)<br>
> > u<br>
> > 1<br>
> > 1<br>
> > b<br>
> > 0<br>
> > 0<br>
> > 0<br>
> > b<br>
> > 1<br>
> > 1<br>
> > 2<br>
> > [0]PETSC ERROR: --------------------- Error Message ------------------------------------<br>
> > [0]PETSC ERROR: Invalid argument!<br>
> > [0]PETSC ERROR: Must be square matrix, rows 3 columns 2!<br>
> > [0]PETSC ERROR: ------------------------------------------------------------------------<br>
> ><br>
> ><br>
> ><br>
> > Could any one point out how to correctly use LSQR solver?<br>
> ><br>
> > <lsqr.c><br>
><br>
><br>
<br>
</div></div></blockquote></div><br>