I’m attempting to multithread a calculation in which I loop over a function that calls on ARPACK’s eigs()
. However, whenever I insert the Threads.@threads
macro in front of the loop I either get an error or Julia crashes altogether. The following MWE reproduces this behavior on my system:
using Arpack
Threads.@threads for i in 1:10
λ, ϕ = eigs(rand(500, 500), maxiter = 1000)
end
If it makes things any clearer, I get the following stacktrace:
ERROR: TaskFailedException:
ARPACKException: unspecified ARPACK error: -9999
Stacktrace:
[1] aupd_wrapper(::Type{T} where T, ::Arpack.var"#matvecA!#24"{Array{Float64,2}}, ::Arpack.var"#18#25", ::Arpack.var"#19#26", ::Int64, ::Bool, ::Bool, ::String, ::Int64, ::Int64, ::String, ::Float64, ::Int64, ::Int64, ::Array{Float64,1}) at C:\Users\Julius\.julia\packages\Arpack\o35I5\src\libarpack.jl:76
[2] _eigs(::Array{Float64,2}, ::LinearAlgebra.UniformScaling{Bool}; nev::Int64, ncv::Int64, which::Symbol, tol::Float64, maxiter::Int64, sigma::Nothing, v0::Array{Float64,1}, ritzvec::Bool) at C:\Users\Julius\.julia\packages\Arpack\o35I5\src\Arpack.jl:181
[3] #eigs#10 at C:\Users\Julius\.julia\packages\Arpack\o35I5\src\Arpack.jl:46 [inlined]
[4] #eigs#9 at C:\Users\Julius\.julia\packages\Arpack\o35I5\src\Arpack.jl:45 [inlined]
[5] macro expansion at .\REPL[2]:2 [inlined]
[6] (::var"#2#threadsfor_fun#3"{UnitRange{Int64}})(::Bool) at .\threadingconstructs.jl:61
[7] (::var"#2#threadsfor_fun#3"{UnitRange{Int64}})() at .\threadingconstructs.jl:28
Stacktrace:
[1] wait(::Task) at .\task.jl:267
[2] top-level scope at .\threadingconstructs.jl:69
The ARPACKException changes from time to time, I’ve also seen 1
and 3
. I get the sense ARPACK is not suitable for multithreading like this, but I don’t really understand why, and I’m curious if there’s a workaround.
This is using Julia 1.4.2 and Arpack 0.4.0, running on a Windows system.