IterativeSolvers.jl
IterativeSolvers.jl copied to clipboard
Support for non-Vector v
Is it the case that while the linear operator may be a custom type, v
must be a vector? I am implementing a shared-memory code that would be much more efficient if I were able to iterate between a custom type and a v::SharedArray
rather than a v::Vector
.
If this is not possible, is it something that the developers are interested in implementing? It is possible that I could work on it.
I don't think the solvers are restricted to Vector
. Have you tried with a SharedVector
?
Some solvers do restrict, not explicitly but by using KrylovSubspace.init!
. For example cg!
:
function init!{T}(K::KrylovSubspace{T}, v::Vector{T})
# K.v = Vector{T}[all(v.==zero(T)) ? v : v/norm(v)]
K.v = Vector{T}[copy(v)]
end
Trying to use SharedArray
throws an error:
julia> s = SharedArray(Float64,(10); init=true);
julia> cg!(s,rand(10,10),rand(10))
ERROR: MethodError: no method matching init!(::IterativeSolvers.KrylovSubspace{Float64,Array{Float64,2}}, ::SharedArray{Float64,1})
Closest candidates are:
init!{T}(::IterativeSolvers.KrylovSubspace{T,OpT}, ::Array{T,1}) at /home/juan/.julia/v0.5/IterativeSolvers/src/krylov.jl:172
in #cg!#38(::Array{Any,1}, ::Function, ::SharedArray{Float64,1}, ::Array{Float64,2}, ::Array{Float64,1}) at /home/juan/.julia/v0.5/IterativeSolvers/src/cg.jl:11
in cg!(::SharedArray{Float64,1}, ::Array{Float64,2}, ::Array{Float64,1}) at /home/juan/.julia/v0.5/IterativeSolvers/src/cg.jl:10
This is not the case for gmres!
:
julia> gmres!(s,rand(10,10),rand(10))
10-element SharedArray{Float64,1}:
31.7301
-68.2552
22.5307
-20.5499
3.4108
6.11011
-28.9851
4.63121
62.258
13.8198
In this case KrylovSubspace
is initialized by wrapping the vector in a function.