[petsc-users] Setting initial guess for KSP solver

Jinquan Zhong jzhong at scsolutions.com
Wed Sep 26 19:43:14 CDT 2012


Jed,

So I need to assembled x before calling KSPSetInitialGuessNonzero().  KSPSolve will take the assembled x as its initial guess.  Correct?  That is


129:   KSPSetFromOptions<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetFromOptions.html#KSPSetFromOptions>(ksp);



131:   if (nonzeroguess) {

132:     PetscScalar<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar> p = .5;

133:     VecSet<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecSet.html#VecSet>(x,p);

134:     KSPSetInitialGuessNonzero<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetInitialGuessNonzero.html#KSPSetInitialGuessNonzero>(ksp,PETSC_TRUE<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_TRUE.html#PETSC_TRUE>);

135:   }

136:

137:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

138:                       Solve the linear system

139:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

140:   /*

141:      Solve linear system

142:   */

143:   KSPSolve<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSolve.html#KSPSolve>(ksp,b,x);


I don’t think the manual specifies this.  I only read

“Tells the iterative solver that the initial guess is nonzero; otherwise KSP<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSP.html#KSP> assumes the initial guess is to be zero (and thus zeros it out before solving).”

Thanks,

Jinquan

From: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] On Behalf Of Jed Brown
Sent: Wednesday, September 26, 2012 5:37 PM
To: PETSc users list
Subject: Re: [petsc-users] Setting initial guess for KSP solver

On Wed, Sep 26, 2012 at 7:33 PM, Jinquan Zhong <jzhong at scsolutions.com<mailto:jzhong at scsolutions.com>> wrote:
        PetscErrorCode  KSPSetInitialGuessNonzero(KSP ksp,PetscBool  flg)

does not provide the option to input x0 though.

It causes the vector X that you pass to KSPSolve to be used as the initial guess. Did you read the man page?

http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetInitialGuessNonzero.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120927/4e11c2d8/attachment-0001.html>


More information about the petsc-users mailing list