# Make variable available on all workers

**URL:** <https://discourse.julialang.org/t/make-variable-available-on-all-workers/112302>\
**Category:** Modelling & Simulations\
**Tags:** distributed\
**Created:** [March 29, 2024, 4:31pm UTC](https://discourse.julialang.org/t/make-variable-available-on-all-workers/112302 "2024-03-29T16:31:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Douven](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igor_douven/32/8433_2.png) [@Igor\_Douven](https://discourse.julialang.org/u/Igor_Douven)\
**Post date:** [March 29, 2024, 4:31pm UTC](https://discourse.julialang.org/t/make-variable-available-on-all-workers/112302/1 "2024-03-29T16:31:43Z")

</div>

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:

```julia
using Distributed
addprocs(...)

@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
end

some_function(population)

```

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

```julia
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])
    end
    return populations, scores
end

```

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?
