-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: numerical_setup! for PETScLinearSolver #104
base: master
Are you sure you want to change the base?
Conversation
I agree there is no need to do so (threw away ns.B), as the (implicit) assumption is that |
src/PETScLinearSolvers.jl
Outdated
@check_error_code PETSC.KSPSetOperators(ns.ksp[],ns.B.mat[],ns.B.mat[]) | ||
# ns.A = A | ||
# ns.B = convert(PETScMatrix,A) | ||
# @check_error_code PETSC.KSPSetOperators(ns.ksp[],ns.B.mat[],ns.B.mat[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure that we do no longer need to call KSPSetOperators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what the manual says:
To solve successive linear systems that have different preconditioner matrices
(i.e., the matrix elements and/or the matrix data structure change), the user
must call KSPSetOperators and KSPSolve for each solve.
which would indicate we do. However, my tests point to this not being the case. This works, for instance:
solver = PETScLinearSolver(mykspsetup)
println("First call")
ns = numerical_setup(symbolic_setup(solver,A),A)
x = allocate_in_domain(A)
fill!(x,0.0)
solve!(x,ns,b)
println("Second call")
map(Ai -> rmul!(Ai,2.0), partition(A))
b *= 2.0
numerical_setup!(ns,A)
x2 = allocate_in_domain(A)
fill!(x2,0.0)
solve!(x2,ns,b)
e = norm(x-x2)
println("Error =", e)
src/PETScLinearSolvers.jl
Outdated
# ns.B = convert(PETScMatrix,A) | ||
# @check_error_code PETSC.KSPSetOperators(ns.ksp[],ns.B.mat[],ns.B.mat[]) | ||
@assert nnz(ns.A) == nnz(A) # This is weak, but it might catch some errors | ||
copy!(ns.B,A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this copy!
call, which are the possible types for A
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, all supported types
We previously threw away PETSc's matrix
ns.B
, and re-set the KSP object (commented code).This is not only unnecessary, but can also cause some issues with MUMPS.
I am not completely sure why, but here are some notes on the issue:
find the pivots.
I think it probably re-orders the matrix internally, and does not re-order it again when we swap it
using
KSPSetOperators
. So when accessing the new (non-permuted) matrix using the old permutation,it throws a stack overflow error.
In fact, when updating the SNES setups in the nonlinear solvers, we do not re-set the matrix,
but use
copy!
instead.