# ParallelDataTransfer.jl with local variables

**URL:** https://discourse.julialang.org/t/paralleldatatransfer-jl-with-local-variables/110916
**Category:** General Usage
**Tags:** package, distributed
**Created:** [February 28, 2024, 6:52pm UTC](https://discourse.julialang.org/t/paralleldatatransfer-jl-with-local-variables/110916 "2024-02-28T18:52:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lgo/32/48751_2.png) [@lgo](https://discourse.julialang.org/u/lgo)
#### Post date: [February 28, 2024, 6:52pm UTC](https://discourse.julialang.org/t/paralleldatatransfer-jl-with-local-variables/110916/1 "2024-02-28T18:52:44Z")

</div>

I want to pass a variable to my workers inside a function (see minimum example below) but I get stuck on passobj. I assume this is because passobj is evaluated at the global scope where the variable is not defined? Is there any way to get this to work?

I work on 0.5.1 for ParallelDataTransfer and Julia 1.8.4.

> using Distributed  
> addprocs(4)
> 
> @everywhere using Distributed, ParallelDataTransfer
> 
> function testPass(a::Vector{Float64})  
> passobj(1, workers(), [:a])  
> end
> 
> testPass(rand(10))

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [February 28, 2024, 7:49pm UTC](https://discourse.julialang.org/t/paralleldatatransfer-jl-with-local-variables/110916/2 "2024-02-28T19:49:13Z")

</div>

> [@lgo](#):
>
> I want to pass a variable to my workers inside a function (see minimum example below) but I get stuck on passobj. I assume this is because passobj is evaluated at the global scope where the variable is not defined? Is there any way to get this to work?

You cannot pass to a local function because that is global dynamic data. What you can do is pass it to a worker that then reads that information in a function by using a global variable. So you’d do:

```julia
function f(x)
   x + a
end

```

and if you send `a` to your worker then it can update the global `a`. You can that get more sophisticated if you can reference and update the reference after the send.
