Skip to content

Commit 5fb8281

Browse files
committed
Add a multithreaded matvec
1 parent 504e134 commit 5fb8281

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/utils.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,43 @@ function approximate_eigenvalues(A, tol, maxiter, symmetric, v0)
9797
end
9898

9999
find_breakdown(::Type{Float64}) = eps(Float64) * 10^6
100-
find_breakdown(::Type{Float32}) = eps(Float64) * 10^3
100+
find_breakdown(::Type{Float32}) = eps(Float64) * 10^3
101+
102+
using Base.Threads
103+
#=function mul!(α::Number, A::SparseMatrixCSC, B::StridedVecOrMat, β::Number, C::StridedVecOrMat)
104+
A.n == size(B, 1) || throw(DimensionMismatch())
105+
A.m == size(C, 1) || throw(DimensionMismatch())
106+
size(B, 2) == size(C, 2) || throw(DimensionMismatch())
107+
nzv = A.nzval
108+
rv = A.rowval
109+
if β != 1
110+
β != 0 ? scale!(C, β) : fill!(C, zero(eltype(C)))
111+
end
112+
for k = 1:size(C, 2)
113+
for col = 1:A.n
114+
αxj = α*B[col,k]
115+
for j = A.colptr[col]:(A.colptr[col + 1] - 1)
116+
C[rv[j], k] += nzv[j]*αxj
117+
end
118+
end
119+
end
120+
C
121+
end
122+
spmatvec(A::SparseMatrixCSC{TA,S}, x::StridedVector{Tx}) where {TA,S,Tx} =
123+
(T = promote_type(TA, Tx); mul!(one(T), A, x, zero(T), similar(x, T, A.m)))=#
124+
125+
# export spmatvec
126+
using Base.Threads
127+
import Base: *
128+
function *(A::SparseMatrixCSC{T,V}, b::Vector{T}) where {T,V}
129+
m, n = size(A)
130+
ret = zeros(T, m)
131+
@threads for i = 1:n
132+
for j in nzrange(A, i)
133+
row = A.rowval[j]
134+
val = A.nzval[j]
135+
ret[row] += val * b[i]
136+
end
137+
end
138+
ret
139+
end

0 commit comments

Comments
 (0)