Skip to content

v0.7 upgrade, comments, bugfixes and cleanup #43

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

Merged
merged 37 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f40ac89
v0.7 support, cleanup, comments and bug fixes
mohamed82008 Aug 1, 2018
7078229
neighbour -> directed strong couplings in comments
mohamed82008 Aug 1, 2018
52b8322
v0.6 backward compatibility
mohamed82008 Aug 1, 2018
2b9e314
v0.6 backward compatibility 2
mohamed82008 Aug 1, 2018
26ba084
fix travis
mohamed82008 Aug 1, 2018
22ba11e
fix package name in travis
mohamed82008 Aug 1, 2018
110e1c5
allow failures for v0.7 and nightly
mohamed82008 Aug 1, 2018
87cb134
allow failures 2
mohamed82008 Aug 1, 2018
e812e22
allow failures 3
mohamed82008 Aug 1, 2018
686222c
AMG -> AlgebraicMultigrid
mohamed82008 Aug 2, 2018
ad2be73
fix travis package name
mohamed82008 Aug 2, 2018
9443fe5
jld -> jld2
mohamed82008 Aug 2, 2018
5248060
add JLD2 to test REQUIRE
mohamed82008 Aug 2, 2018
3913da1
disallow failures for v0.7 and nightly
mohamed82008 Aug 2, 2018
8bc5deb
Generalize direct interpol for non-symmetric matrices and edge cases
mohamed82008 Aug 2, 2018
e89a333
use callable structs
mohamed82008 Aug 12, 2018
d193468
jld2 -> jl files
mohamed82008 Aug 12, 2018
aee7c2d
callable Pinv and some inplace
mohamed82008 Aug 12, 2018
cd43348
log only when log is true
mohamed82008 Aug 12, 2018
4d3929f
add preallocation and block support machinery
mohamed82008 Aug 12, 2018
e0b9684
allow preallocating x
mohamed82008 Aug 12, 2018
b70d841
srand -> seed!
mohamed82008 Aug 12, 2018
37d9576
save top residual calculation when preconditioning
mohamed82008 Aug 12, 2018
716973b
pre-alloc all multiplications
mohamed82008 Aug 12, 2018
f67246c
remove FileIO and JLD2 from test REQUIRE
mohamed82008 Aug 12, 2018
f0f22f0
Fix solve and preconditioner API allowing different initializations
mohamed82008 Aug 12, 2018
a495879
remove using FileIO from runtests.jl
mohamed82008 Aug 12, 2018
20948ec
fix v0.6 tests
mohamed82008 Aug 12, 2018
933f9b7
allow failure on nightly
mohamed82008 Aug 12, 2018
ca7ba87
try v1.0 in Travis and fix nightly
mohamed82008 Aug 12, 2018
e15ef16
pre-allocate in Jacobi smoother
mohamed82008 Aug 12, 2018
7ed4c68
block smoothing, remove branches, and parallel Jacobi
mohamed82008 Aug 12, 2018
b519b1c
AbstractVector -> AbstractArray and minor fixes
mohamed82008 Aug 12, 2018
df9db80
fix tests
mohamed82008 Aug 12, 2018
76ac8f1
Make \ call ldiv!
mohamed82008 Aug 15, 2018
c467855
fix v0.6 perf
mohamed82008 Aug 19, 2018
94bd0df
fix type stability of ifelse
mohamed82008 Aug 19, 2018
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
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.6
IterativeSolvers 0.4.1
julia 0.7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we still maintain v0.6 compatibility?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe through Compat

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mostly supported thanks to Compat, just needed a few @static if statements.

IterativeSolvers 0.7.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use v0.6.0 because IterativeSolvers 0.7.0 needs Julia 0.7

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually more stuff need to be changed, I was running the tests wrongly. This too yes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, ping me when you're done making all those. We should add v0.7 to .travis.yml as well. Thanks a lot for this PR! There was a lot of dead code on the classical AMG which I didn't have time to get to.

Compat 1.0.0
2 changes: 2 additions & 0 deletions src/AMG.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module AMG
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also modify this module name to AlgebraicMultigrid ? This was AMG from the time it was ranjanan/AMG.jl


import IterativeSolvers: gauss_seidel!
using Compat, Compat.LinearAlgebra
using Compat.SparseArrays, Compat.Printf
using Base.Threads

const MT = false
Expand Down
2 changes: 1 addition & 1 deletion src/aggregate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function aggregation(::StandardAggregation, S::SparseMatrixCSC{T,R}) where {T,R}
if minimum(x) == -1
mask = x .!= -1
I = collect(R, 1:n)[mask]
J = x[mask] + R(1)
J = x[mask] .+ R(1)
#J = x[mask] + 1
V = ones(eltype(S), length(J))
AggOp = sparse(J,I,V,N,M)
Expand Down
4 changes: 2 additions & 2 deletions src/aggregation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ function extend_hierarchy!(levels, strength, aggregate, smooth,

A, B, bsr_flag
end
construct_R(::HermitianSymmetry, P) = P'
construct_R(::HermitianSymmetry, P) = copy(P')

function fit_candidates(AggOp, B, tol = 1e-10)

A = AggOp.'
A = copy(AggOp')
n_fine, n_coarse = size(A)
n_col = n_coarse

Expand Down
59 changes: 26 additions & 33 deletions src/classical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ struct Solver{S,T,P,PS}
max_coarse::Int64
end

function ruge_stuben{Ti,Tv}(A::SparseMatrixCSC{Ti,Tv};
function ruge_stuben(A::SparseMatrixCSC{Ti,Tv};
strength = Classical(0.25),
CF = RS(),
presmoother = GaussSeidel(),
postsmoother = GaussSeidel(),
max_levels = 10,
max_coarse = 10)
max_coarse = 10) where {Ti,Tv}

s = Solver(strength, CF, presmoother,
postsmoother, max_levels, max_levels)
Expand All @@ -29,7 +29,7 @@ function ruge_stuben{Ti,Tv}(A::SparseMatrixCSC{Ti,Tv};
MultiLevel(levels, A, presmoother, postsmoother)
end

function extend_heirarchy!{Ti,Tv}(levels::Vector{Level{Ti,Tv}}, strength, CF, A::SparseMatrixCSC{Ti,Tv})
function extend_heirarchy!(levels::Vector{Level{Ti,Tv}}, strength, CF, A::SparseMatrixCSC{Ti,Tv}) where {Ti,Tv}
S, T = strength_of_connection(strength, A)
splitting = split_nodes(CF, S)
P, R = direct_interpolation(A, T, splitting)
Expand All @@ -38,50 +38,43 @@ function extend_heirarchy!{Ti,Tv}(levels::Vector{Level{Ti,Tv}}, strength, CF, A:
end

function direct_interpolation(A, T, splitting)

fill!(T.nzval, eltype(A)(1.))
fill!(T.nzval, eltype(A)(1))
T .= A .* T
Pp = rs_direct_interpolation_pass1(T, A, splitting)
Pp .= Pp .+ 1

Pp = rs_direct_interpolation_pass1(T, splitting)
Px, Pj, Pp = rs_direct_interpolation_pass2(A, T, splitting, Pp)

Pj .= Pj .+ 1

R = SparseMatrixCSC(maximum(Pj), size(A, 1), Pp, Pj, Px)
P = R'
P = copy(R')

P, R
end


function rs_direct_interpolation_pass1(T, A, splitting)

Bp = zeros(Int, size(A.colptr))
n = size(A, 1)
nnz = 0
for i = 1:n
if splitting[i] == C_NODE
nnz += 1
else
for j in nzrange(T, i)
row = T.rowval[j]
if splitting[row] == C_NODE && row != i
nnz += 1
# calculates the number of nonzeros in each column of the interpolation matrix
function rs_direct_interpolation_pass1(T, splitting)
n = size(T, 2)
Bp = ones(Int, n+1)
nnzplus1 = 1
for i = 1:n
if splitting[i] == C_NODE
nnzplus1 += 1
else
for j in nzrange(T, i)
row = T.rowval[j]
if splitting[row] == C_NODE && row != i
nnzplus1 += 1
end
end
end
end
Bp[i+1] = nnz
end
Bp
Bp[i+1] = nnzplus1
end
Bp
end


function rs_direct_interpolation_pass2(A::SparseMatrixCSC{Tv,Ti},
function rs_direct_interpolation_pass2(A::SparseMatrixCSC{Tv,Ti},
T::SparseMatrixCSC{Tv, Ti},
splitting::Vector{Ti},
Bp::Vector{Ti}) where {Tv,Ti}


Bx = zeros(Tv, Bp[end] - 1)
Bj = zeros(Ti, Bp[end] - 1)
Expand Down Expand Up @@ -157,7 +150,7 @@ function rs_direct_interpolation_pass1(T, A, splitting)
m[i] = sum
sum += splitting[i]
end
Bj .= m[Bj]
Bj .= m[Bj] .+ 1

Bx, Bj, Bp
Bx, Bj, Bp
end
8 changes: 4 additions & 4 deletions src/multilevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract type CoarseSolver end
struct Pinv <: CoarseSolver
end

MultiLevel{Ti,Tv}(l::Vector{Level{Ti,Tv}}, A::SparseMatrixCSC{Ti,Tv}, presmoother, postsmoother) =
MultiLevel(l::Vector{Level{Ti,Tv}}, A::SparseMatrixCSC{Ti,Tv}, presmoother, postsmoother) where {Ti,Tv} =
MultiLevel(l, A, Pinv(), presmoother, postsmoother)
Base.length(ml) = length(ml.levels) + 1

Expand Down Expand Up @@ -92,12 +92,12 @@ Keyword Arguments
* log::Bool - return vector of residuals along with solution

"""
function solve{T}(ml::MultiLevel, b::Vector{T},
function solve(ml::MultiLevel, b::Vector{T},
cycle::Cycle = V();
maxiter::Int = 100,
tol::Float64 = 1e-5,
verbose::Bool = false,
log::Bool = false)
log::Bool = false) where {T}

A = length(ml) == 1 ? ml.final_A : ml.levels[1].A
V = promote_type(eltype(A), eltype(b))
Expand Down Expand Up @@ -149,4 +149,4 @@ function __solve(v::V, ml, x, b, lvl)
x
end

coarse_solver(::Pinv, A, b) = pinv(full(A)) * b
coarse_solver(::Pinv, A, b) = pinv(Matrix(A)) * b
6 changes: 3 additions & 3 deletions src/preconditioner.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base: \, *, A_ldiv_B!, A_mul_B!
import LinearAlgebra: \, *, ldiv!, mul!

struct Preconditioner
ml::MultiLevel
Expand All @@ -9,5 +9,5 @@ aspreconditioner(ml::MultiLevel) = Preconditioner(ml)
\(p::Preconditioner, b) = solve(p.ml, b, maxiter = 1, tol = 1e-12)
*(p::Preconditioner, b) = p.ml.levels[1].A * x

A_ldiv_B!(x, p::Preconditioner, b) = copy!(x, p \ b)
A_mul_B!(b, p::Preconditioner, x) = A_mul_B!(b, p.ml.levels[1].A, x)
ldiv!(x, p::Preconditioner, b) = copyto!(x, p \ b)
mul!(b, p::Preconditioner, x) = mul!(b, p.ml.levels[1].A, x)
2 changes: 1 addition & 1 deletion src/smoother.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function weight(::LocalWeighting, S, ω)
end
D_inv_S = scale_rows(S, D)
# eltype(S)(ω) * D_inv_S
scale!(D_inv_S, eltype(S)(ω))
rmul!(D_inv_S, eltype(S)(ω))
end

#approximate_spectral_radius(A) =
Expand Down
Loading