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

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

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 ?

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.

1 Like

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

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

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 ?

No, it’s because D is not defined on your other worker processes (see here):

julia> using Distributed

julia> D = Distributed

julia> nprocs()

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

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

julia> @everywhere D = Distributed

julia> @everywhere println(D.myid())
      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.

Got it, thank you again…