Skip to content

Commit 1433c7e

Browse files
committed
fix sparspak solves in multithreaded loop
1 parent a07ee0b commit 1433c7e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ext/LinearSolveSparspakExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function SciMLBase.solve!(
4141
cache::LinearSolve.LinearCache, alg::SparspakFactorization; kwargs...)
4242
A = cache.A
4343
if cache.isfresh
44-
if cache.cacheval !== nothing && alg.reuse_symbolic
44+
if !(cache.cacheval === PREALLOCATED_SPARSEPAK) && alg.reuse_symbolic
4545
fact = sparspaklu!(LinearSolve.@get_cacheval(cache, :SparspakFactorization),
4646
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
4747
nonzeros(A)))

test/basictests.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,34 @@ end
679679
u = solve!(cache)
680680
@test norm(u - u0, Inf) < 1.0e-8
681681
end
682+
683+
@testset "ParallelSolves" begin
684+
n=1000
685+
@info "ParallelSolves: Threads.nthreads()=$(Threads.nthreads())"
686+
A_sparse = 10I - sprand(n, n, 0.01)
687+
B = [rand(n), rand(n)]
688+
U = [A_sparse \ B[i] for i in 1:2]
689+
sol = similar(U)
690+
691+
Threads.@threads for i in 1:2
692+
sol[i] = solve(LinearProblem(A_sparse, B[i]), UMFPACKFactorization())
693+
end
694+
695+
for i in 1:2
696+
@test sol[i] U[i]
697+
end
698+
699+
Threads.@threads for i in 1:2
700+
sol[i] = solve(LinearProblem(A_sparse, B[i]), KLUFactorization())
701+
end
702+
for i in 1:2
703+
@test sol[i] U[i]
704+
end
705+
706+
Threads.@threads for i in 1:2
707+
sol[i] = solve(LinearProblem(A_sparse, B[i]), SparspakFactorization())
708+
end
709+
for i in 1:2
710+
@test sol[i] U[i]
711+
end
712+
end

0 commit comments

Comments
 (0)