Make variable available on all workers

Hi all,

I’d like to run an evolutionary algorithm which starts with a population of agents and then lets that evolve for a number of generations. To make this not too slow, parts of the algorithm are parallelized. If I run a single update (from one generation to the next), everything is simple. Schematically, it looks as follows:

using Distributed

@everywhere population = ... # vector of agents

function some_function(v::Vector{Agent})
    scores = pmap(i -> v[i], 1:N)
    return w, scores # new population of agents (w), together with scores of the input population


This works fine. But to run this repeatedly, for several generations, I’d like to wrap it all into one function, something like

function run_evo(numb_agents::Int, numb_generations::Int)
    start_population = f(numb_agents) # with f some function creating a population of numb_agents agents
    populations = []
    scores = []
    push!(populations, start_population)
    for i in 1:numb_generations
        b = some_function(populations[end]) # same function as above
        push!(populations, b[1])
        push!(scores, b[2])
    return populations, scores

This doesn’t work (well, it runs, but not in parallel), because although some_function calls pmap, start_population and populations are not available on other workers. Is there a simple way to make them available?