2
votes

Let's say I have some data :: Vector{Float64} and a function f!(data::Vector{Float64}, i::Int) that calculates some value from it, modifying it in the process.

answers = pmap([1,2,3,4]) do i
    f!(data, i)
end

Is this safe to do? Does each worker have its own copy of data, or should I explicitly copy(data) on all workers?

1

1 Answers

3
votes

That is safe to do and will create a closure that puts the data in the function and sends the function with the data to each process. If you use a CachingPool it will make sure that data is only sent to each worker once (in Julia v0.7 and 1.0 this will be done by default).