Skip to content
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

Added parallel jacobi #10

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ExtendableSparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include("preconditioners.jl")
include("sprand.jl")

export SparseMatrixLNK,ExtendableSparseMatrix,flush!,nnz, sprand!,sprand_sdd!, fdrand,fdrand!
export JacobiPreconditioner, ILU0Preconditioner, updateindex!
export JacobiPreconditioner, ILU0Preconditioner, ParallelJacobiPreconditioner, updateindex!

export colptrs
end # module
37 changes: 37 additions & 0 deletions src/parallel_jacobi.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
struct ParallelJacobiPreconditioner{Tv, Ti} <: AbstractExtendablePreconditioner{Tv,Ti}
extmatrix::ExtendableSparseMatrix{Tv,Ti}
invdiag::Array{Tv,1}
end

function update!(precon::ParallelJacobiPreconditioner)
cscmatrix=precon.extmatrix.cscmatrix
invdiag=precon.invdiag
n=cscmatrix.n
Threads.@threads for i=1:n
@inbounds invdiag[i]=1.0/cscmatrix[i,i]
end
precon
end

function ParallelJacobiPreconditioner(extmatrix::ExtendableSparseMatrix{Tv,Ti}) where {Tv,Ti}
@assert size(extmatrix,1)==size(extmatrix,2)
flush!(extmatrix)
invdiag=Array{Tv,1}(undef,extmatrix.cscmatrix.n)
precon=JacobiPreconditioner{Tv, Ti}(extmatrix,invdiag)
update!(precon)
end

ParallelJacobiPreconditioner(cscmatrix::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti}=ParallelJacobiPreconditioner(ExtendableSparseMatrix(cscmatrix))


function LinearAlgebra.ldiv!(u::AbstractArray{T,1} where T, precon::ParallelJacobiPreconditioner, v::AbstractArray{T,1} where T)
invdiag=precon.invdiag
n=length(invdiag)
Threads.@threads for i=1:n
@inbounds u[i]=invdiag[i]*v[i]
end
end

function LinearAlgebra.ldiv!(precon::ParallelJacobiPreconditioner, v::AbstractArray{T,1} where T)
ldiv!(v, precon, v)
end
2 changes: 2 additions & 0 deletions src/preconditioners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ timestamp!(precon::AbstractExtendablePreconditioner)= precon.pattern_timestamp=t

include("jacobi.jl")
include("ilu0.jl")

include("parallel_jacobi.jl")