# How to use macro that has been moved from base to a package (e.g. @everywhere)?

**URL:** https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295
**Category:** General Usage
**Created:** [August 30, 2018, 8:32am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295 "2018-08-30T08:32:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [August 30, 2018, 8:32am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295/1 "2018-08-30T08:32:54Z")

</div>

I am trying to port the following Notebook to Julia 1.0:

> **[Jupyter Notebook Viewer](https://nbviewer.org/github/sylvaticus/juliatutorial/blob/master/assets/Parallel%20computing.ipynb)**
>
> Check out this Jupyter notebook!

I am stock on the following point:

`@everywhere println(myid())`

Julia 0.7 warns me with:

> WARNING: Base.@everywhere is deprecated: it has been moved to the standard library package `Distributed`.  
> Add `using Distributed` to your imports.

But even if I do that I still have the warning (of course I did try `Distributed.@everywhere`, but it doesn’t seems to be the right syntax).  
Which is the right syntax to use a macro that resides within a package ?

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [August 30, 2018, 8:43am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295/2 "2018-08-30T08:43:02Z")

</div>

Have you restarted the session? Once used, the binding to `@everywhere` still points to the old binding and thus you still get the deprecation warning. After a reload and fresh `using`, it will point to the package.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [August 30, 2018, 8:44am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295/3 "2018-08-30T08:44:05Z")

</div>

yes, exactly… restarting the kernel was fine… and now I know why. Thank you.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [August 30, 2018, 8:52am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295/4 "2018-08-30T08:52:20Z")

</div>

An other “strange” behaviour… I updated the code for Julia 1.0 with

```julia
using BenchmarkTools, Distributed, LinearAlgebra
D = Distributed
LA = LinearAlgebra

```

I can then use `D` instead of typing everytime `Distributed`, but on this line I still need to use `Distributed`. If I use `D` it returns me an error `UndefVarError: D not defined`:

`D.@everywhere println(Distributed.myid())`

hmmm… let me guess… the macro `@everywhere` in the `Distributed` package creates a scope that isolate me from the rest of my script ? But so it means I can’t access global variables from the macro ?

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [August 30, 2018, 8:58am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295/5 "2018-08-30T08:58:38Z")

</div>

No, it’s because `D` is not defined on your other worker processes (see [here](https://docs.julialang.org/en/stable/manual/parallel-computing/#Code-Availability-and-Loading-Packages-1)):

```julia
julia> using Distributed

julia> D = Distributed
Distributed

julia> nprocs()
2

julia> @everywhere println(myid())
1
      From worker 2: 2

julia> @everywhere println(D.myid())
1
ERROR: On worker 2:
UndefVarError: D not defined
#<snip>

julia> @everywhere D = Distributed

julia> @everywhere println(D.myid())
1
      From worker 2: 2

```

Note the error, it specifies where the error happened - in this case on worker 2. The first call to `myid()` succeeds because I started julia with `julia -p 1`, which creates a worker process and implicitly loads the Distributed package on all workers.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [August 30, 2018, 9:21am UTC](https://discourse.julialang.org/t/how-to-use-macro-that-has-been-moved-from-base-to-a-package-e-g-everywhere/14295/6 "2018-08-30T09:21:25Z")

</div>

> [@Sukera](#):
>
> @everywhere D = Distributed

Got it, thank you again…
