# Exploiting parallel Julia's auto-global shipping from inside functions and other submodules?

**URL:** <https://discourse.julialang.org/t/exploiting-parallel-julias-auto-global-shipping-from-inside-functions-and-other-submodules/53185>\
**Category:** General Usage\
**Created:** [January 12, 2021, 2:45am UTC](https://discourse.julialang.org/t/exploiting-parallel-julias-auto-global-shipping-from-inside-functions-and-other-submodules/53185 "2021-01-12T02:45:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 12, 2021, 2:45am UTC](https://discourse.julialang.org/t/exploiting-parallel-julias-auto-global-shipping-from-inside-functions-and-other-submodules/53185/1 "2021-01-12T02:45:56Z")

</div>

The fact that Julia automatically ships globals from Main to workers for you is a super useful construct,

```julia
using Distributed
addprocs(1)

x = [1,2,3]

@fetch x .+ 1 # x was shipped to worker here
@fetch x .+ 2 # x wasn't shipped again since its unchanged

@everywhere 2 @isdefined(x) # true

```

But put that same code inside another module and it doesn’t work because this only works for globals in _Main_. Or put it inside a function and now `x` isnt a global, so both `@fetch` commands will send x as part of a closure (which is unwanted if `x` is something big and costly to send).

So is there any way to hook into the same machinery that works for globals in Main but from other places? Guessing you could do it with lots of `@eval Main ...` but hoping maybe there’s a better solution. Also there’s no doubt some more by-hand solutions you could do but really I just want the same mechanism that works in Main to take care of checking whether an object has changed and needs to be resent for me.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 12, 2021, 2:51am UTC](https://discourse.julialang.org/t/exploiting-parallel-julias-auto-global-shipping-from-inside-functions-and-other-submodules/53185/2 "2021-01-12T02:51:33Z")

</div>

Related behavior sometimes can cause headache:

> [@How to NOT interpolate on remote worker?](https://discourse.julialang.org/t/how-to-not-interpolate-on-remote-worker/53027/1):
>
> julia\> using Distributed julia\> addprocs(2); julia\> @everywhere a = [1,2] julia\> @everywhere println(a) [1, 2] From worker 3: [1, 2] From worker 2: [1, 2] julia\> a = 5 5 julia\> @everywhere println(a) 5 From worker 2: [1, 2] From worker 3: [1, 2] julia\> @fetchfrom 3 a[2] ERROR: On worker 3: BoundsError Stacktrace: julia\> @everywhere println(a) 5 From worker 2: [1, 2] From worker 3: 5 this above behavior is weird, how do I access the a …

So I don’t think it’s a good idea to be too automatic about this
