6.3.5. Other KSP Options

Up: Contents Next: Preconditioners Previous: Understanding the Operator's Spectrum

To obtain the solution vector and right hand side from a KSP context, one uses

   ierr = KSPGetSolution(KSP ksp,Vec *x); 
   ierr = KSPGetRhs(KSP ksp,Vec *rhs); 
During the iterative process the solution may not yet have been calculated or it may be stored in a different location. To access the approximate solution during the iterative process, one uses the command
   ierr = KSPBuildSolution(KSP ksp,Vec w,Vec *v); 
where the solution is returned in v. The user can optionally provide a vector in w as the location to store the vector; however, if w is PETSC_NULL, space allocated by PETSc in the KSP context is used. One should not destroy this vector. For certain KSP methods, (e.g., GMRES), the construction of the solution is expensive, while for many others it requires not even a vector copy.

Access to the residual is done in a similar way with the command

   ierr = KSPBuildResidual(KSP ksp,Vec t,Vec w,Vec *v); 
Again, for GMRES and certain other methods this is an expensive operation.


Up: Contents Next: Preconditioners Previous: Understanding the Operator's Spectrum