I have no idea why the following code errors:
using Base.Threads
A = Dict{Int, Vector{Float64}}()
# A = rand(10, 10) # OK
foreach(i->A[i] = rand(10), 1:10)
@threads for i in eachindex(A) # ERROR: TaskFailedException in case that A is a Dict()
sum(A[i])
end
ERROR: TaskFailedException:
MethodError: no method matching unsafe_getindex(::Base.KeySet{Int64,Dict{Int64,Array{Float64,1}}}, ::Int64)
Closest candidates are:
unsafe_getindex(::StepRangeLen{T,#s66,#s65} where #s65<:Base.TwicePrecision where #s66<:Base.TwicePrecision, ::Integer) where T at twiceprecision.jl:447
unsafe_getindex(::StepRangeLen{T,R,S} where S where R, ::Integer) where T at range.jl:647
unsafe_getindex(::LinRange, ::Integer) at range.jl:657
It seems like that @threads does not allow iteration over Dict(); If A
is an array e.g., A = rand(10, 10)
no such error occurs.