xref: /petsc/doc/manual/advanced.md (revision 7f296bb328fcd4c99f2da7bfe8ba7ed8a4ebceee)
1*7f296bb3SBarry Smith(ch_advanced)=
2*7f296bb3SBarry Smith
3*7f296bb3SBarry Smith# Advanced Features of Matrices and Solvers
4*7f296bb3SBarry Smith
5*7f296bb3SBarry SmithThis chapter introduces additional features of the PETSc matrices and
6*7f296bb3SBarry Smithsolvers.
7*7f296bb3SBarry Smith
8*7f296bb3SBarry Smith(sec_matsub)=
9*7f296bb3SBarry Smith
10*7f296bb3SBarry Smith## Extracting Submatrices
11*7f296bb3SBarry Smith
12*7f296bb3SBarry SmithOne can extract a (parallel) submatrix from a given (parallel) using
13*7f296bb3SBarry Smith
14*7f296bb3SBarry Smith```
15*7f296bb3SBarry SmithMatCreateSubMatrix(Mat A,IS rows,IS cols,MatReuse call,Mat *B);
16*7f296bb3SBarry Smith```
17*7f296bb3SBarry Smith
18*7f296bb3SBarry SmithThis extracts the `rows` and `cols` of the matrix `A` into
19*7f296bb3SBarry Smith`B`. If call is `MAT_INITIAL_MATRIX` it will create the matrix
20*7f296bb3SBarry Smith`B`. If call is `MAT_REUSE_MATRIX` it will reuse the `B` created
21*7f296bb3SBarry Smithwith a previous call. This function is used internally by `PCFIELDSPLIT`.
22*7f296bb3SBarry Smith
23*7f296bb3SBarry SmithOne can also extract one or more submatrices per MPI process with
24*7f296bb3SBarry Smith
25*7f296bb3SBarry Smith```
26*7f296bb3SBarry SmithMatCreateSubMatrices(Mat A,PetscInt n,IS rows[],IS cols[],MatReuse call,Mat *B[]);
27*7f296bb3SBarry Smith```
28*7f296bb3SBarry Smith
29*7f296bb3SBarry SmithThis extracts n (zero or more) matrices with the `rows[k]` and `cols[k]` of the matrix `A` into an array of
30*7f296bb3SBarry Smithsequential matrices `B[k]` on this process. If call is `MAT_INITIAL_MATRIX` it will create the array of matrices
31*7f296bb3SBarry Smith`B`. If call is `MAT_REUSE_MATRIX` it will reuse the `B` created
32*7f296bb3SBarry Smithwith a previous call. The `IS` arguments are sequential. The array of matrices should be destroyed with `MatDestroySubMatrices()`.
33*7f296bb3SBarry SmithThis function is used by `PCBJACOBI` and `PCASM`.
34*7f296bb3SBarry Smith
35*7f296bb3SBarry SmithEach submatrix may be parallel, existing on a `MPI_Comm` associated with each pair of `IS` `rows[k]` and `cols[k]`,
36*7f296bb3SBarry Smithusing
37*7f296bb3SBarry Smith
38*7f296bb3SBarry Smith```
39*7f296bb3SBarry SmithMatCreateSubMatricesMPI(Mat A,PetscInt n,IS rows[],IS cols[],MatReuse call,Mat *B[]);
40*7f296bb3SBarry Smith```
41*7f296bb3SBarry Smith
42*7f296bb3SBarry SmithFinally this version has a specialization
43*7f296bb3SBarry Smith
44*7f296bb3SBarry Smith```
45*7f296bb3SBarry SmithMatGetMultiProcBlock(Mat A, MPI_Comm subComm, MatReuse scall,Mat *subMat);
46*7f296bb3SBarry Smith```
47*7f296bb3SBarry Smith
48*7f296bb3SBarry Smithwhere collections of non-overlapping MPI processes share a single parallel matrix on their sub-communicator.
49*7f296bb3SBarry SmithThis function is used by `PCBJACOBI` and `PCASM`.
50*7f296bb3SBarry Smith
51*7f296bb3SBarry SmithThe routine
52*7f296bb3SBarry Smith
53*7f296bb3SBarry Smith```
54*7f296bb3SBarry SmithMatCreateRedundantMatrix(Mat A,PetscInt nsubcomm,MPI_Comm subcomm,MatReuse reuse,Mat *matredundant);
55*7f296bb3SBarry Smith```
56*7f296bb3SBarry Smith
57*7f296bb3SBarry Smithwhere `nsubcomm` copies of the entire matrix are stored, one on each `subcomm`. The routine `PetscSubcommCreate()` and its
58*7f296bb3SBarry Smith`PetscSubcomm` object may, but need not be, used to construct the `subcomm`.
59*7f296bb3SBarry Smith
60*7f296bb3SBarry SmithThe routine
61*7f296bb3SBarry Smith
62*7f296bb3SBarry Smith```
63*7f296bb3SBarry SmithMatMPIAdjToSeq(Mat A,Mat *B);
64*7f296bb3SBarry Smith```
65*7f296bb3SBarry Smith
66*7f296bb3SBarry Smithis a specialization that duplicates an entire `MATMPIADJ` matrix on each MPI process.
67*7f296bb3SBarry Smith
68*7f296bb3SBarry Smith(sec_matfactor)=
69*7f296bb3SBarry Smith
70*7f296bb3SBarry Smith## Matrix Factorization
71*7f296bb3SBarry Smith
72*7f296bb3SBarry SmithNormally, PETSc users will access the matrix solvers through the `KSP`
73*7f296bb3SBarry Smithinterface, as discussed in {any}`ch_ksp`, but the
74*7f296bb3SBarry Smithunderlying factorization and triangular solve routines are also directly
75*7f296bb3SBarry Smithaccessible to the user.
76*7f296bb3SBarry Smith
77*7f296bb3SBarry SmithThe ILU, LU, ICC, Cholesky, and QR matrix factorizations are split into two or three
78*7f296bb3SBarry Smithstages depending on the user’s needs. The first stage is to calculate an
79*7f296bb3SBarry Smithordering for the matrix. The ordering generally is done to reduce fill
80*7f296bb3SBarry Smithin a sparse factorization; it does not make much sense for a dense
81*7f296bb3SBarry Smithmatrix.
82*7f296bb3SBarry Smith
83*7f296bb3SBarry Smith```
84*7f296bb3SBarry SmithMatGetOrdering(Mat matrix,MatOrderingType type,IS* rowperm,IS* colperm);
85*7f296bb3SBarry Smith```
86*7f296bb3SBarry Smith
87*7f296bb3SBarry SmithThe currently available alternatives for the ordering `type` are
88*7f296bb3SBarry Smith
89*7f296bb3SBarry Smith- `MATORDERINGNATURAL` - Natural
90*7f296bb3SBarry Smith- `MATORDERINGND` - Nested Dissection
91*7f296bb3SBarry Smith- `MATORDERING1WD` - One-way Dissection
92*7f296bb3SBarry Smith- `MATORDERINGRCM` - Reverse Cuthill-McKee
93*7f296bb3SBarry Smith- `MATORDERINGQMD` - Quotient Minimum Degree
94*7f296bb3SBarry Smith
95*7f296bb3SBarry SmithThese orderings can also be set through the options database.
96*7f296bb3SBarry Smith
97*7f296bb3SBarry SmithCertain matrix formats may support only a subset of these. All of
98*7f296bb3SBarry Smiththese orderings are symmetric at the moment; ordering routines that are
99*7f296bb3SBarry Smithnot symmetric may be added. Currently we support orderings only for
100*7f296bb3SBarry Smithsequential matrices.
101*7f296bb3SBarry Smith
102*7f296bb3SBarry SmithUsers can add their own ordering routines by providing a function with
103*7f296bb3SBarry Smiththe calling sequence
104*7f296bb3SBarry Smith
105*7f296bb3SBarry Smith```
106*7f296bb3SBarry Smithint reorder(Mat A,MatOrderingType type,IS* rowperm,IS* colperm);
107*7f296bb3SBarry Smith```
108*7f296bb3SBarry Smith
109*7f296bb3SBarry SmithHere `A` is the matrix for which we wish to generate a new ordering,
110*7f296bb3SBarry Smith`type` may be ignored and `rowperm` and `colperm` are the row and
111*7f296bb3SBarry Smithcolumn permutations generated by the ordering routine. The user
112*7f296bb3SBarry Smithregisters the ordering routine with the command
113*7f296bb3SBarry Smith
114*7f296bb3SBarry Smith```
115*7f296bb3SBarry SmithMatOrderingRegister(MatOrderingType ordname,char *path,char *sname,PetscErrorCode (*reorder)(Mat,MatOrderingType,IS*,IS*)));
116*7f296bb3SBarry Smith```
117*7f296bb3SBarry Smith
118*7f296bb3SBarry SmithThe input argument `ordname` is a string of the user’s choice,
119*7f296bb3SBarry Smitheither an ordering defined in `petscmat.h` or the name
120*7f296bb3SBarry Smithof a new ordering introduced by the user. See the code in
121*7f296bb3SBarry Smith`src/mat/impls/order/sorder.c` and other files in that
122*7f296bb3SBarry Smithdirectory for examples on how the reordering routines may be written.
123*7f296bb3SBarry Smith
124*7f296bb3SBarry SmithOnce the reordering routine has been registered, it can be selected for
125*7f296bb3SBarry Smithuse at runtime with the command line option
126*7f296bb3SBarry Smith`-pc_factor_mat_ordering_type` `ordname`. If reordering from the API, the
127*7f296bb3SBarry Smithuser should provide the `ordname` as the second input argument of
128*7f296bb3SBarry Smith`MatGetOrdering()`.
129*7f296bb3SBarry Smith
130*7f296bb3SBarry SmithPETSc matrices interface to a variety of external factorization/solver packages via the `MatSolverType` which can be
131*7f296bb3SBarry Smith`MATSOLVERSUPERLU_DIST`, `MATSOLVERMUMPS`, `MATSOLVERPASTIX`, `MATSOLVERMKL_PARDISO`, `MATSOLVERMKL_CPARDISO`,
132*7f296bb3SBarry Smith`MATSOLVERUMFPACK`, `MATSOLVERCHOLMOD`, `MATSOLVERKLU`,
133*7f296bb3SBarry Smith`MATSOLVERCUSPARSE`, and `MATSOLVERCUDA`.
134*7f296bb3SBarry SmithThe last three of which can run on GPUs, while `MATSOLVERSUPERLU_DIST` can partially run on GPUs.
135*7f296bb3SBarry SmithSee {any}`doc_linsolve` for a table of the factorization based solvers in PETSc.
136*7f296bb3SBarry Smith
137*7f296bb3SBarry SmithMost of these packages compute their own orderings and cannot use ones provided so calls to the following routines with those
138*7f296bb3SBarry Smithpackages can pass NULL as the `IS` permutations.
139*7f296bb3SBarry Smith
140*7f296bb3SBarry SmithThe following routines perform incomplete and complete, in-place, symbolic, and
141*7f296bb3SBarry Smithnumerical factorizations for symmetric and nonsymmetric matrices:
142*7f296bb3SBarry Smith
143*7f296bb3SBarry Smith```
144*7f296bb3SBarry SmithMatICCFactor(Mat matrix,IS permutation,const MatFactorInfo *info);
145*7f296bb3SBarry SmithMatCholeskyFactor(Mat matrix,IS permutation,const MatFactorInfo *info);
146*7f296bb3SBarry SmithMatILUFactor(Mat matrix,IS rowpermutation,IS columnpermutation,const MatFactorInfo *info);
147*7f296bb3SBarry SmithMatLUFactor(Mat matrix,IS rowpermutation,IS columnpermutation,const MatFactorInfo *info);
148*7f296bb3SBarry SmithMatQRFactor(Mat matrix, IS columnpermutation, const MatFactorInfo *info);
149*7f296bb3SBarry Smith```
150*7f296bb3SBarry Smith
151*7f296bb3SBarry SmithThe argument `info->fill > 1` is the predicted fill expected in the
152*7f296bb3SBarry Smithfactored matrix, as a ratio of the original fill. For example,
153*7f296bb3SBarry Smith`info->fill = 2.0` would indicate that one expects the factored matrix
154*7f296bb3SBarry Smithto have twice as many nonzeros as the original.
155*7f296bb3SBarry Smith
156*7f296bb3SBarry SmithFor sparse matrices it is very unlikely that the factorization is
157*7f296bb3SBarry Smithactually done in-place. More likely, new space is allocated for the
158*7f296bb3SBarry Smithfactored matrix and the old space deallocated, but to the user it
159*7f296bb3SBarry Smithappears in-place because the factored matrix replaces the unfactored
160*7f296bb3SBarry Smithmatrix.
161*7f296bb3SBarry Smith
162*7f296bb3SBarry SmithThe two factorization stages can also be performed separately, by using
163*7f296bb3SBarry Smiththe preferred out-of-place mode, first one obtains that matrix object that will
164*7f296bb3SBarry Smithhold the factor using
165*7f296bb3SBarry Smith
166*7f296bb3SBarry Smith```
167*7f296bb3SBarry SmithMatGetFactor(Mat matrix,MatSolverType package,MatFactorType ftype,Mat *factor);
168*7f296bb3SBarry Smith```
169*7f296bb3SBarry Smith
170*7f296bb3SBarry Smithand then performs the factorization
171*7f296bb3SBarry Smith
172*7f296bb3SBarry Smith```
173*7f296bb3SBarry SmithMatICCFactorSymbolic(Mat factor,Mat matrix,IS perm,const MatFactorInfo *info);
174*7f296bb3SBarry SmithMatCholeskyFactorSymbolic(Mat factor,Mat matrix,IS perm,const MatFactorInfo *info);
175*7f296bb3SBarry SmithMatCholeskyFactorNumeric(Mat factor,Mat matrix,const MatFactorInfo);
176*7f296bb3SBarry Smith
177*7f296bb3SBarry SmithMatILUFactorSymbolic(Mat factor,Mat matrix,IS rowperm,IS colperm,const MatFactorInfo *info);
178*7f296bb3SBarry SmithMatLUFactorSymbolic(Mat factor,Mat matrix,IS rowperm,IS colperm,const MatFactorInfo *info);
179*7f296bb3SBarry SmithMatLUFactorNumeric(Mat factor,Mat matrix,const MatFactorInfo *info);
180*7f296bb3SBarry Smith
181*7f296bb3SBarry SmithMatQRFactorSymbolic(Mat factor,Mat matrix,IS perm,const MatFactorInfo *info);
182*7f296bb3SBarry SmithMatQRFactorNumeric(Mat factor,Mat matrix,const MatFactorInfo *info);
183*7f296bb3SBarry Smith```
184*7f296bb3SBarry Smith
185*7f296bb3SBarry SmithIn this case, the contents of the matrix `factor` is undefined between
186*7f296bb3SBarry Smiththe symbolic and numeric factorization stages. It is possible to reuse
187*7f296bb3SBarry Smiththe symbolic factorization. For the second and succeeding
188*7f296bb3SBarry Smithfactorizations, one simply calls the numerical factorization with a new
189*7f296bb3SBarry Smithinput `matrix` and the *same* factored `factor` matrix. It is
190*7f296bb3SBarry Smith*essential* that the new input matrix have exactly the same nonzero
191*7f296bb3SBarry Smithstructure as the original factored matrix. (The numerical factorization
192*7f296bb3SBarry Smithmerely overwrites the numerical values in the factored matrix and does
193*7f296bb3SBarry Smithnot disturb the symbolic portion, thus enabling reuse of the symbolic
194*7f296bb3SBarry Smithphase.) In general, calling `XXXFactorSymbolic` with a dense matrix
195*7f296bb3SBarry Smithwill do nothing except allocate the new matrix; the `XXXFactorNumeric`
196*7f296bb3SBarry Smithroutines will do all of the work.
197*7f296bb3SBarry Smith
198*7f296bb3SBarry SmithWhy provide the plain `XXXFactor` routines when one could simply call
199*7f296bb3SBarry Smiththe two-stage routines? The answer is that if one desires in-place
200*7f296bb3SBarry Smithfactorization of a sparse matrix, the intermediate stage between the
201*7f296bb3SBarry Smithsymbolic and numeric phases cannot be stored in a `factor` matrix, and
202*7f296bb3SBarry Smithit does not make sense to store the intermediate values inside the
203*7f296bb3SBarry Smithoriginal matrix that is being transformed. We originally made the
204*7f296bb3SBarry Smithcombined factor routines do either in-place or out-of-place
205*7f296bb3SBarry Smithfactorization, but then decided that this approach was not needed and
206*7f296bb3SBarry Smithcould easily lead to confusion.
207*7f296bb3SBarry Smith
208*7f296bb3SBarry SmithWe do not provide our own sparse matrix factorization with pivoting
209*7f296bb3SBarry Smithfor numerical stability. This is because trying to both reduce fill and
210*7f296bb3SBarry Smithdo pivoting can become quite complicated. Instead, we provide a poor
211*7f296bb3SBarry Smithstepchild substitute. After one has obtained a reordering, with
212*7f296bb3SBarry Smith`MatGetOrdering(Mat A,MatOrdering type,IS *row,IS *col)` one may call
213*7f296bb3SBarry Smith
214*7f296bb3SBarry Smith```
215*7f296bb3SBarry SmithMatReorderForNonzeroDiagonal(Mat A,PetscReal tol,IS row, IS col);
216*7f296bb3SBarry Smith```
217*7f296bb3SBarry Smith
218*7f296bb3SBarry Smithwhich will try to reorder the columns to ensure that no values along the
219*7f296bb3SBarry Smithdiagonal are smaller than `tol` in a absolute value. If small values
220*7f296bb3SBarry Smithare detected and corrected for, a nonsymmetric permutation of the rows
221*7f296bb3SBarry Smithand columns will result. This is not guaranteed to work, but may help if
222*7f296bb3SBarry Smithone was simply unlucky in the original ordering. When using the `KSP`
223*7f296bb3SBarry Smithsolver interface the option `-pc_factor_nonzeros_along_diagonal <tol>`
224*7f296bb3SBarry Smithmay be used. Here, `tol` is an optional tolerance to decide if a value
225*7f296bb3SBarry Smithis nonzero; by default it is `1.e-10`.
226*7f296bb3SBarry Smith
227*7f296bb3SBarry SmithThe external `MatSolverType`'s `MATSOLVERSUPERLU_DIST` and `MATSOLVERMUMPS`
228*7f296bb3SBarry Smithdo manage numerical pivoting internal to their API.
229*7f296bb3SBarry Smith
230*7f296bb3SBarry SmithThe external factorization packages each provide a wide number of options to chose from,
231*7f296bb3SBarry Smithdetails on these may be found by consulting the manual page for the solver package, such as,
232*7f296bb3SBarry Smith`MATSOLVERSUPERLU_DIST`. Most of the options can be easily set via the options database
233*7f296bb3SBarry Smitheven when the factorization solvers are accessed via `KSP`.
234*7f296bb3SBarry Smith
235*7f296bb3SBarry SmithOnce a matrix has been factored, it is natural to solve linear systems.
236*7f296bb3SBarry SmithThe following four routines enable this process:
237*7f296bb3SBarry Smith
238*7f296bb3SBarry Smith```
239*7f296bb3SBarry SmithMatSolve(Mat A,Vec x, Vec y);
240*7f296bb3SBarry SmithMatSolveTranspose(Mat A, Vec x, Vec y);
241*7f296bb3SBarry SmithMatSolveAdd(Mat A,Vec x, Vec y, Vec w);
242*7f296bb3SBarry SmithMatSolveTransposeAdd(Mat A, Vec x, Vec y, Vec w);
243*7f296bb3SBarry Smith```
244*7f296bb3SBarry Smith
245*7f296bb3SBarry Smithmatrix `A` of these routines must have been obtained from a
246*7f296bb3SBarry Smithfactorization routine; otherwise, an error will be generated. In
247*7f296bb3SBarry Smithgeneral, the user should use the `KSP` solvers introduced in the next
248*7f296bb3SBarry Smithchapter rather than using these factorization and solve routines
249*7f296bb3SBarry Smithdirectly.
250*7f296bb3SBarry Smith
251*7f296bb3SBarry SmithSome of the factorizations also support solves with multiple right-hand sides stored in a `Mat` using
252*7f296bb3SBarry Smith
253*7f296bb3SBarry Smith```
254*7f296bb3SBarry SmithMatMatSolve(Mat A,Mat B,Mat X);
255*7f296bb3SBarry Smith```
256*7f296bb3SBarry Smith
257*7f296bb3SBarry Smithand
258*7f296bb3SBarry Smith
259*7f296bb3SBarry Smith```
260*7f296bb3SBarry SmithMatMatSolveTranspose(Mat A,Mat B,Mat X);
261*7f296bb3SBarry Smith```
262*7f296bb3SBarry Smith
263*7f296bb3SBarry SmithFinally, `MATSOLVERMUMPS`, provides access to Schur complements obtained after partial factorizations as well
264*7f296bb3SBarry Smithas the inertia of a matrix via `MatGetInertia()`.
265*7f296bb3SBarry Smith
266*7f296bb3SBarry Smith(sec_matmatproduct)=
267*7f296bb3SBarry Smith
268*7f296bb3SBarry Smith## Matrix-Matrix Products
269*7f296bb3SBarry Smith
270*7f296bb3SBarry SmithPETSc matrices provide code for computing various matrix-matrix products. This section will introduce the two sets of routines
271*7f296bb3SBarry Smithavailable. For now consult `MatCreateProduct()` and `MatMatMult()`.
272*7f296bb3SBarry Smith
273*7f296bb3SBarry Smith## Creating PC's Directly
274*7f296bb3SBarry Smith
275*7f296bb3SBarry SmithUsers obtain their preconditioner contexts from the `KSP`
276*7f296bb3SBarry Smithcontext with the command `KSPGetPC()`. It is possible to create,
277*7f296bb3SBarry Smithmanipulate, and destroy `PC` contexts directly, although this
278*7f296bb3SBarry Smithcapability should rarely be needed. To create a `PC` context, one uses
279*7f296bb3SBarry Smiththe command
280*7f296bb3SBarry Smith
281*7f296bb3SBarry Smith```
282*7f296bb3SBarry SmithPCCreate(MPI_Comm comm,PC *pc);
283*7f296bb3SBarry Smith```
284*7f296bb3SBarry Smith
285*7f296bb3SBarry SmithThe routine
286*7f296bb3SBarry Smith
287*7f296bb3SBarry Smith```
288*7f296bb3SBarry SmithPCSetType(PC pc,PCType method);
289*7f296bb3SBarry Smith```
290*7f296bb3SBarry Smith
291*7f296bb3SBarry Smithsets the preconditioner method to be used. The routine
292*7f296bb3SBarry Smith
293*7f296bb3SBarry Smith```
294*7f296bb3SBarry SmithPCSetOperators(PC pc,Mat Amat,Mat Pmat);
295*7f296bb3SBarry Smith```
296*7f296bb3SBarry Smith
297*7f296bb3SBarry Smithset the matrices that are to be used with the preconditioner. The
298*7f296bb3SBarry Smithroutine
299*7f296bb3SBarry Smith
300*7f296bb3SBarry Smith```
301*7f296bb3SBarry SmithPCGetOperators(PC pc,Mat *Amat,Mat *Pmat);
302*7f296bb3SBarry Smith```
303*7f296bb3SBarry Smith
304*7f296bb3SBarry Smithreturns the values set with `PCSetOperators()`.
305*7f296bb3SBarry Smith
306*7f296bb3SBarry SmithThe preconditioners in PETSc can be used in several ways. The two most
307*7f296bb3SBarry Smithbasic routines simply apply the preconditioner or its transpose and are
308*7f296bb3SBarry Smithgiven, respectively, by
309*7f296bb3SBarry Smith
310*7f296bb3SBarry Smith```
311*7f296bb3SBarry SmithPCApply(PC pc,Vec x,Vec y);
312*7f296bb3SBarry SmithPCApplyTranspose(PC pc,Vec x,Vec y);
313*7f296bb3SBarry Smith```
314*7f296bb3SBarry Smith
315*7f296bb3SBarry SmithIn particular, for a preconditioner matrix, `B`, that has been set via
316*7f296bb3SBarry Smith`PCSetOperators(pc,Amat,Pmat)`, the routine PCApply(pc,x,y) computes
317*7f296bb3SBarry Smith$y = B^{-1} x$ by solving the linear system $By = x$ with
318*7f296bb3SBarry Smiththe specified preconditioner method.
319*7f296bb3SBarry Smith
320*7f296bb3SBarry SmithAdditional preconditioner routines are
321*7f296bb3SBarry Smith
322*7f296bb3SBarry Smith```
323*7f296bb3SBarry SmithPCApplyBAorAB(PC pc,PCSide right,Vec x,Vec y,Vec work);
324*7f296bb3SBarry SmithPCApplyBAorABTranspose(PC pc,PCSide right,Vec x,Vec y,Vec work);
325*7f296bb3SBarry SmithPCApplyRichardson(PC pc,Vec x,Vec y,Vec work,PetscReal rtol,PetscReal atol, PetscReal dtol,PetscInt maxits,PetscBool zeroguess,PetscInt *outits,PCRichardsonConvergedReason*);
326*7f296bb3SBarry Smith```
327*7f296bb3SBarry Smith
328*7f296bb3SBarry SmithThe first two routines apply the action of the matrix followed by the
329*7f296bb3SBarry Smithpreconditioner or the preconditioner followed by the matrix depending on
330*7f296bb3SBarry Smithwhether the `right` is `PC_LEFT` or `PC_RIGHT`. The final routine
331*7f296bb3SBarry Smithapplies `its` iterations of Richardson’s method. The last three
332*7f296bb3SBarry Smithroutines are provided to improve efficiency for certain Krylov subspace
333*7f296bb3SBarry Smithmethods.
334*7f296bb3SBarry Smith
335*7f296bb3SBarry SmithA `PC` context that is no longer needed can be destroyed with the
336*7f296bb3SBarry Smithcommand
337*7f296bb3SBarry Smith
338*7f296bb3SBarry Smith```
339*7f296bb3SBarry SmithPCDestroy(PC *pc);
340*7f296bb3SBarry Smith```
341