16.3. Unimportant Details of KSP

Up: Contents Next: Unimportant Details of PC Previous: Matrix Factorization

Again, virtually all users should use KSP through the SLES interface and, thus, will not need to know the details that follow.

It is possible to generate a Krylov subspace context with the command

   ierr = KSPCreate(MPI_Comm comm,KSP *kps); 
Before using the Krylov context, one must set the matrix-vector multiplication routine and the preconditioner with the commands
   ierr = PCSetOperators(PC pc,Mat mat,Mat pmat,MatStructure flag); 
   ierr = KSPSetPC(KSP ksp,PC pc); 
In addition, the KSP solver must be initialized with
   ierr = KSPSetUp(KSP ksp); 
Solving a linear system is done with the command
   ierr = KSPSolve(KSP ksp,int *its); 
Finally, the KSP context should be destroyed with
   ierr = KSPDestroy(KSP ksp); 
It may seem strange to put the matrix in the preconditioner rather than directly in the KSP; this decision was the result of much agonizing. The reason is that for SSOR with Eisenstat's trick, and certain other preconditioners, the preconditioner has to change the matrix-vector multiply. This procedure could not be done cleanly if the matrix were stashed in the KSP context that PC cannot access.

Any preconditioner can supply not only the preconditioner, but also a routine that essentially performs a complete Richardson step. The reason for this is mainly SOR. To use SOR in the Richardson framework, that is,

un+1 = un + B(f - A un),

is much more expensive than just updating the values. With this addition it is reasonable to state that all our iterative methods are obtained by combining a preconditioner from the PC component with a Krylov method from the KSP component. This strategy makes things much simpler conceptually, so (we hope) clean code will result. Note: We had this idea already implicitly in older versions of SLES, but, for instance, just doing Gauss-Seidel with Richardson in old SLES was much more expensive than it had to be. With PETSc 2.0 this should not be a problem.


Up: Contents Next: Unimportant Details of PC Previous: Matrix Factorization