Adam Wheeler
Adam Wheeler

Reputation: 154

local variable access by workers in julia

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?

Upvotes: 2

Views: 346

Answers (1)

Chris Rackauckas
Chris Rackauckas

Reputation: 19132

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).

Upvotes: 3

Related Questions