I would like to run the function f() on all my 4 processors (intel i7) and fetch the rands sum, as follows:
using Distributed;
@everywhere function f()
return sum(rand(10000))
end
@sync for w in workers()
@async begin
res = @spawnat w f()
values[w-1] = fetch(res)
end
end
But, getting the following error:
ERROR: TaskFailedException
nested task error: MethodError: no method matching setindex!(::typeof(values), ::Float64, ::Int64)
Stacktrace:
[1] macro expansion
@ ./REPL[58]:4 [inlined]
[2] (::var"#68#70"{Channel{Any}, Int64})()
@ Main ./task.jl:411
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base ./task.jl:369
[2] top-level scope
@ task.jl:388
Please guide me in resolving the issue!