Skip to content

Commit

Permalink
Removing exchange! after solve
Browse files Browse the repository at this point in the history
  • Loading branch information
amartinhuertas committed Nov 12, 2021
1 parent 0379aa1 commit 9b21f58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/PETScLinearSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Algebra.solve!(x::PVector,ns::PETScLinearSolverNS,b::PVector)
copy!(X,x)
Y = convert(PETScVector,X)
solve!(Y,ns,b)
_copy_and_exchange!(x,Y)
copy!(x,Y)
end


Expand Down
20 changes: 2 additions & 18 deletions src/PETScNonlinearSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,14 @@ function _setup_cache(x::AbstractVector,nls::PETScNonlinearSolver,op::NonlinearO
jac_petsc_mat_A, jac_petsc_mat_A)
end

# Helper private functions to implement the solve! methods below.
# It allows to execute the solve! methods below in a serial context, i.e.,
# whenever
function _myexchange!(x::AbstractVector)
x
end
function _myexchange!(x::PVector)
exchange!(x)
end

function _copy_and_exchange!(a::AbstractVector,b::PETScVector)
copy!(a,b.vec[])
_myexchange!(a)
end


function Algebra.solve!(x::T,
nls::PETScNonlinearSolver,
op::NonlinearOperator,
cache::PETScNonlinearSolverCache{<:T}) where T <: AbstractVector

@assert cache.op === op
@check_error_code PETSC.SNESSolve(cache.snes[],C_NULL,cache.x_petsc.vec[])
_copy_and_exchange!(x,cache.x_petsc)
copy!(x,cache.x_petsc)
cache
end

Expand All @@ -186,6 +170,6 @@ function Algebra.solve!(x::AbstractVector,nls::PETScNonlinearSolver,op::Nonlinea
PETSC.SNESSetJacobian(cache.snes[],cache.jac_petsc_mat_A.mat[],cache.jac_petsc_mat_A.mat[],fptr,ctx)

@check_error_code PETSC.SNESSolve(cache.snes[],C_NULL,cache.x_petsc.vec[])
_copy_and_exchange!(x,cache.x_petsc)
copy!(x,cache.x_petsc)
cache
end

0 comments on commit 9b21f58

Please sign in to comment.