I’m trying to use distributed computing without having to pass a large Vector to each worker. Each worker only needs a single item from the Vector. I should also clarify that I cannot use SharedArrays (at least to my knowledge) because for my actual code, the Vector is filled with complex objects (not bits as done here).
Example below:
using Distributed
addprocs(4)
@everywhere begin
function expensive_function(y)
return y * 2 + 1.0
end
struct Container
x::Vector{Float64}
end
end
function run_parallel(container)
results = pmap(1:length(container.x)) do i
expensive_function(container.x[i])
end
return results
end
n = 500
x = ones(n^3)
container = Container(x)
run_parallel(container)
The container is unnecessary but is closer to how my actual code is setup. When running this code it is clear that a copy of container is passed to each worker, when in reality expensive_function
only needs a single entry at a time.
I know I can use pmap(iterator, distributed=false)
but with that option, my code starts crashing within a try/catch block. So first I’d like to exhaust any options with distributed=true.
Thanks!