The following loop works without threading but fails because it cant seem to index the iterator:
arr1 = [5:10;]
arr2 = [20:5:30;]
comb = Base.Iterators.product(arr1,arr2)
function threadedComb(comb)
Threads.@threads for c in comb
println(c)
end
end
function singleComb(comb)
for c in comb
println(c)
end
end
Without threading
singleComb(comb)
(5, 20)
(6, 20)
(7, 20)
(8, 20)
(9, 20)
(10, 20)
(5, 25)
(6, 25)
(7, 25)
(8, 25)
(9, 25)
(10, 25)
(5, 30)
(6, 30)
(7, 30)
(8, 30)
(9, 30)
(10, 30)
With threading:
threadedComb(comb)
ERROR: TaskFailedException:
MethodError: no method matching firstindex(::Base.Iterators.ProductIterator{Tuple{Array{Int64,1},Array{Int64,1}}})
Closest candidates are:
firstindex(::Core.SimpleVector) at essentials.jl:601
firstindex(::Cmd) at process.jl:639
firstindex(::Base64.Buffer) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Base64/src/buffer.jl:18
...
Stacktrace:
[1] (::var"#409#threadsfor_fun#37"{Base.Iterators.ProductIterator{Tuple{Array{Int64,1},Array{Int64,1}}}})(::Bool) at ./threadingconstructs.jl:46
[2] (::var"#409#threadsfor_fun#37"{Base.Iterators.ProductIterator{Tuple{Array{Int64,1},Array{Int64,1}}}})() at ./threadingconstructs.jl:28
Stacktrace:
[1] wait(::Task) at ./task.jl:267
[2] macro expansion at ./threadingconstructs.jl:69 [inlined]
[3] threadedComb(::Base.Iterators.ProductIterator{Tuple{Array{Int64,1},Array{Int64,1}}}) at /mnt/evo512/insync/Software_a1/testCUDA/test_threaded_combos.jl:8
[4] top-level scope at /mnt/evo512/insync/Software_a1/testCUDA/test_threaded_combos.jl:48
How can I modify threadedComb
to allow threaded access?