2.4.5. Linear Solvers

Up: Contents Next: Error Checking Previous: Matrices

After creating the matrix and vectors that define a linear system, Ax = b, the user can then use SLES to solve the system with the following sequence of commands:

   ierr = SLESCreate(MPI_Comm comm,SLES *sles);  
   ierr = SLESSetOperators(SLES sles,Mat A,Mat PrecA,MatStructure flag); 
   ierr = SLESSetFromOptions(SLES sles); 
   ierr = SLESSolve(SLES sles,Vec b,Vec x,int *its); 
   ierr = SLESDestroy(SLES sles); 
The user first creates the SLES context and sets the operators associated with the system (linear system matrix and optionally different preconditioning matrix). The user then sets various options for customized solution, solves the linear system, and finally destroys the SLES context. We emphasize the command SLESSetFromOptions(), which enables the user to customize the linear solution method at runtime by using the options database, which is discussed in Section Runtime Options . Through this database, the user not only can select an iterative method and preconditioner, but also can prescribe the convergence tolerance, set various monitoring routines, etc. (see, e.g., Figure 7 ).

Chapter SLES: Linear Equations Solvers describes in detail the SLES package, including the PC and KSP components for preconditioners and Krylov subspace methods.


Up: Contents Next: Error Checking Previous: Matrices