Some questions about modifying the linear system in SNES
$\quad$ Hello, I use `SNESComputeJacobianDefault` to build a preconditioning matrix for JFNK and use `MatGetRowSumAbs` to obtain the vector for scaling. When I modify the preconditioning matrix in formJacobian[`SNESSetJacobian`] and modify rhs and the solution variables in preSolve[`KSPSetPreSolve`] and postSolve[`KSPSetPostSolve`] as scaling, I encounter the following questions. 1. If I need to scale the solution variables, do I need to call `SNESGetSolutionUpdate` to scale the increment vector instead of the solution vector in `postSolve(KSP /*ksp*/, Vec rhs, Vec x, void * ctx)`? 2. Whether this can achieve the same scaling effect as `-pc_jacobi_type rowl1`, so that the built-in preconditioner scheme of petsc can be applied on the basis of the above modified linear system? Or whether this will affect the residual used to construct the matrix through the finite difference and then lead to the wrong scaling effect?
You don't want to scale the matrix manually. -pc_jacobi_type rowl1 do what you want. And Jacobi is a more common choice. Mark On Thu, Jan 8, 2026 at 1:02 PM 陈培群 <[email protected]> wrote:
$\quad$ Hello, I use `SNESComputeJacobianDefault` to build a preconditioning matrix for JFNK and use `MatGetRowSumAbs` to obtain the vector for scaling. When I modify the preconditioning matrix in formJacobian [`SNESSetJacobian`] and modify rhs and the solution variables in preSolve[ `KSPSetPreSolve`] and postSolve[`KSPSetPostSolve`] as scaling, I encounter the following questions. 1. If I need to scale the solution variables, do I need to call ` SNESGetSolutionUpdate` to scale the increment vector instead of the solution vector in `postSolve(KSP /*ksp*/, Vec rhs, Vec x, void * ctx)`?
2. Whether this can achieve the same scaling effect as `-pc_jacobi_type rowl1`, so that the built-in preconditioner scheme of petsc can be applied on the basis of the above modified linear system? Or whether this will affect the residual used to construct the matrix through the finite difference and then lead to the wrong scaling effect?
$\quad$ Thanks. What I want is to use `rowl1` as scaling and then apply other preconditioner, but when I use `-pc_type composite -pc_composite_type multiplicative -pc_composite_pcs jacobi,...`, I can't set `-pc_jacobi_type rowl1`. Can `-sub_pc_type` or `PCCOMPOSITE` achieve the above requirements? $\quad$ I couldn't find the relevant command line. so I manually scale the linear system in SNES. But it seems that when the preconditioning matrix is constructed by the finite difference method based on the residual, the use of a row scaling similar to the left preconditioner will cause the residual to change and lead to repeated scaling. Is that so? $\quad$ Then how does the left preconditioner in petsc do not affect the residuals used to construct the preconditioning matrix? At 2026-01-09 03:00:52, "Mark Adams" <[email protected]> wrote: You don't want to scale the matrix manually. -pc_jacobi_type rowl1 do what you want. And Jacobi is a more common choice. Mark On Thu, Jan 8, 2026 at 1:02 PM 陈培群 <[email protected]> wrote: $\quad$ Hello, I use `SNESComputeJacobianDefault` to build a preconditioning matrix for JFNK and use `MatGetRowSumAbs` to obtain the vector for scaling. When I modify the preconditioning matrix in formJacobian[`SNESSetJacobian`] and modify rhs and the solution variables in preSolve[`KSPSetPreSolve`] and postSolve[`KSPSetPostSolve`] as scaling, I encounter the following questions. 1. If I need to scale the solution variables, do I need to call `SNESGetSolutionUpdate` to scale the increment vector instead of the solution vector in `postSolve(KSP /*ksp*/, Vec rhs, Vec x, void * ctx)`? 2. Whether this can achieve the same scaling effect as `-pc_jacobi_type rowl1`, so that the built-in preconditioner scheme of petsc can be applied on the basis of the above modified linear system? Or whether this will affect the residual used to construct the matrix through the finite difference and then lead to the wrong scaling effect?
$\quad$`-pc_type composite -pc_composite_type multiplicative -pc_composite_pcs jacobi,ilu -sub_0_pc_jacobi_type rowl1` can set the type, but there is still no way to set the left preconditioner or right preconditioner. Is there a command line such as `-sub_0_ksp_pc_side left -sub_1_ksp_pc_side right`? At 2026-01-09 09:57:01, "陈培群 " <[email protected]> wrote: $\quad$ Thanks. What I want is to use `rowl1` as scaling and then apply other preconditioner, but when I use `-pc_type composite -pc_composite_type multiplicative -pc_composite_pcs jacobi,...`, I can't set `-pc_jacobi_type rowl1`. Can `-sub_pc_type` or `PCCOMPOSITE` achieve the above requirements? $\quad$ I couldn't find the relevant command line. so I manually scale the linear system in SNES. But it seems that when the preconditioning matrix is constructed by the finite difference method based on the residual, the use of a row scaling similar to the left preconditioner will cause the residual to change and lead to repeated scaling. Is that so? $\quad$ Then how does the left preconditioner in petsc do not affect the residuals used to construct the preconditioning matrix? At 2026-01-09 03:00:52, "Mark Adams" <[email protected]> wrote: You don't want to scale the matrix manually. -pc_jacobi_type rowl1 do what you want. And Jacobi is a more common choice. Mark On Thu, Jan 8, 2026 at 1:02 PM 陈培群 <[email protected]> wrote: $\quad$ Hello, I use `SNESComputeJacobianDefault` to build a preconditioning matrix for JFNK and use `MatGetRowSumAbs` to obtain the vector for scaling. When I modify the preconditioning matrix in formJacobian[`SNESSetJacobian`] and modify rhs and the solution variables in preSolve[`KSPSetPreSolve`] and postSolve[`KSPSetPostSolve`] as scaling, I encounter the following questions. 1. If I need to scale the solution variables, do I need to call `SNESGetSolutionUpdate` to scale the increment vector instead of the solution vector in `postSolve(KSP /*ksp*/, Vec rhs, Vec x, void * ctx)`? 2. Whether this can achieve the same scaling effect as `-pc_jacobi_type rowl1`, so that the built-in preconditioner scheme of petsc can be applied on the basis of the above modified linear system? Or whether this will affect the residual used to construct the matrix through the finite difference and then lead to the wrong scaling effect?
I told you how to try out your idea by modifying the PETSc source code in KSP to implement the scaling you want in KSPSolve. You are wasting a lot of your time and other people's time trying to do it other ways that will not work. It appears you may be intimidated by the thought of actually changing the PETSc source code to accomplish what you would like to try. Don't be, it is just source code you can modify to try your idea. Doing it will give you the scaling you want; there is no other way to achieve this scaling using any other part of PETSc that is not designed for this purpose.
On Jan 8, 2026, at 8:57 PM, 陈培群 <[email protected]> wrote:
$\quad$ Thanks. What I want is to use `rowl1` as scaling and then apply other preconditioner, but when I use `-pc_type composite -pc_composite_type multiplicative -pc_composite_pcs jacobi,...`, I can't set `-pc_jacobi_type rowl1`. Can `-sub_pc_type` or `PCCOMPOSITE` achieve the above requirements? $\quad$ I couldn't find the relevant command line. so I manually scale the linear system in SNES. But it seems that when the preconditioning matrix is constructed by the finite difference method based on the residual, the use of a row scaling similar to the left preconditioner will cause the residual to change and lead to repeated scaling. Is that so? $\quad$ Then how does the left preconditioner in petsc do not affect the residuals used to construct the preconditioning matrix?
At 2026-01-09 03:00:52, "Mark Adams" <[email protected]> wrote:
You don't want to scale the matrix manually. -pc_jacobi_type rowl1 do what you want. And Jacobi is a more common choice.
Mark
On Thu, Jan 8, 2026 at 1:02 PM 陈培群 <[email protected] <mailto:[email protected]>> wrote:
$\quad$ Hello, I use `SNESComputeJacobianDefault` to build a preconditioning matrix for JFNK and use `MatGetRowSumAbs` to obtain the vector for scaling. When I modify the preconditioning matrix in formJacobian[`SNESSetJacobian`] and modify rhs and the solution variables in preSolve[`KSPSetPreSolve`] and postSolve[`KSPSetPostSolve`] as scaling, I encounter the following questions. 1. If I need to scale the solution variables, do I need to call `SNESGetSolutionUpdate` to scale the increment vector instead of the solution vector in `postSolve(KSP /*ksp*/, Vec rhs, Vec x, void * ctx)`? 2. Whether this can achieve the same scaling effect as `-pc_jacobi_type rowl1`, so that the built-in preconditioner scheme of petsc can be applied on the basis of the above modified linear system? Or whether this will affect the residual used to construct the matrix through the finite difference and then lead to the wrong scaling effect?
participants (3)
-
Barry Smith -
Mark Adams -
陈培群