The docstring for Distributed.pgenerate
says
Results are returned in order as they become available.
which is exactly what I need. However, it doesn’t seem to be working this way, instead, the results are only returned after all results have been calculated, e.g.:
julia> using Distributed
julia> addprocs(2)
2-element Array{Int64,1}:
2
3
julia> for i in Distributed.pgenerate(i->(sleep(0.5); println("Computed $i"); i), 1:4)
println("Received $i")
end
From worker 2: Computed 1
From worker 3: Computed 2
From worker 2: Computed 3
From worker 3: Computed 4
Received 1
Received 2
Received 3
Received 4
I was expecting to have seen “Received 1” and “Received 2” before 3 and 4 finished. Am I doing anything wrong, or is there some other way to achieve this? I’ve tried with Julia 1.3, 1.4, and 1.5.