# How may I send data to other processes within a function?

**URL:** <https://discourse.julialang.org/t/how-may-i-send-data-to-other-processes-within-a-function/15080>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 17, 2018, 4:20pm UTC](https://discourse.julialang.org/t/how-may-i-send-data-to-other-processes-within-a-function/15080 "2018-09-17T16:20:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shipengcheng1230](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shipengcheng1230/32/4089_2.png) [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)\
**Post date:** [September 17, 2018, 4:20pm UTC](https://discourse.julialang.org/t/how-may-i-send-data-to-other-processes-within-a-function/15080/1 "2018-09-17T16:20:38Z")

</div>

Hello, I would like to send some data to other processes in a function, however, it is not successful. Only when I `@spawnat` in the Main module is it able to show up on the var table and be accessible within `@everywhere`. I must be missing something here. Thank you in advance!

```julia
julia> using Distributed

julia> addprocs(4)

julia> a = 123456;

julia> @everywhere using InteractiveUtils

julia> function send_my_data(data)
           @sync begin
               for p in workers()
                   @async @spawnat p data
               end
           end
       end

julia> send_my_data(a)

# sending the data fails as from var table
julia> @fetchfrom 2 varinfo()
name size summary
–––– –––– –––––––
Base Module 
Core Module 
Main Module 

# This indicates no `a` existing on other processes
julia> @everywhere begin a end
ERROR: On worker 2:
UndefVarError: a not defined ...

# However, this shows there is an `a` on other processes
julia> remotecall_fetch(()->a, 2)
123456

```

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [September 18, 2018, 5:42am UTC](https://discourse.julialang.org/t/how-may-i-send-data-to-other-processes-within-a-function/15080/2 "2018-09-18T05:42:19Z")

</div>

Check out [https://github.com/ChrisRackauckas/ParallelDataTransfer.jl/](https://github.com/ChrisRackauckas/ParallelDataTransfer.jl/)

---

<div class="post-metadata">

**Author:** ![shipengcheng1230](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shipengcheng1230/32/4089_2.png) [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)\
**Post date:** [September 19, 2018, 8:34pm UTC](https://discourse.julialang.org/t/how-may-i-send-data-to-other-processes-within-a-function/15080/3 "2018-09-19T20:34:27Z")

</div>

Thank you, I wasn’t aware of this tools before.
