[petsc-users] Setting initial guess for KSP solver

Matthew Knepley knepley at gmail.com
Thu Sep 27 06:39:50 CDT 2012


On Wed, Sep 26, 2012 at 8:45 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> On Wed, Sep 26, 2012 at 7:43 PM, Jinquan Zhong <jzhong at scsolutions.com>wrote:
>
>>  Jed,****
>>
>> ** **
>>
>> So I need to assembled x before calling KSPSetInitialGuessNonzero().  KSPSolve
>> will take the assembled x as its initial guess.  Correct?
>>
>
No you do not need to "assemble" the vector before calling
KSPSetInitialGuessNonzero(). You need to
assemble it before calling KSPSolve().

   Matt


> Yes
>
>
>> 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>
>> 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
>> ****
>>
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120927/59cad445/attachment.html>


More information about the petsc-users mailing list