Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import Distributed; Distributed.@everywhere x = 2 does not work #28966

Closed
cossio opened this issue Aug 30, 2018 · 5 comments
Closed

import Distributed; Distributed.@everywhere x = 2 does not work #28966

cossio opened this issue Aug 30, 2018 · 5 comments
Labels
parallelism Parallel or distributed computation

Comments

@cossio
Copy link
Contributor

cossio commented Aug 30, 2018

This works fine:

using Distributed; @everywhere x = 2

but

import Distributed; Distributed.@everywhere x = 2
# ERROR: LoadError: UndefVarError: @everywhere not defined

gives an error.

@vchuravy
Copy link
Member

julia> import Distributed; Distributed.@everywhere x = 2
ERROR: LoadError: UndefVarError: @everywhere not defined
in expression starting at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\macros.jl:182

Looks like the macro

return esc(:(@everywhere $procs() $ex))
assumes that @everywhere is in the namespace.

d61b054 and x-ref 23164

@JeffBezanson JeffBezanson added the parallelism Parallel or distributed computation label Sep 5, 2018
@ibadr
Copy link

ibadr commented Feb 20, 2019

Also, this fails with the same error, despite using Distributed

const parallel = true
if !parallel
    println("not parallel")
else
    using Distributed; @everywhere x = 2
    println("parallel")
end

@ibadr
Copy link

ibadr commented Feb 20, 2019

For now, this slight tweak works for me

const parallel = true
if !parallel
    println("not parallel")
else
    using Distributed
    Distributed.remotecall_eval(Main, procs(), :(x = 2)) # in lieu of @everywhere x = 2
    println("parallel")
end

@martinholters
Copy link
Member

@ibadr That's a different issue: The parser tries to expand the macro before the using is evaluated, because the parser processes the whole if/else/end before anything of it is evaluated.

@fredrikekre
Copy link
Member

GitHub doesn't autoclose issues from commit messages any more? fixed by #32144

JeffBezanson pushed a commit that referenced this issue Jun 6, 2019
JeffBezanson pushed a commit that referenced this issue Jun 7, 2019
KristofferC pushed a commit that referenced this issue Jun 9, 2019
KristofferC pushed a commit that referenced this issue Aug 26, 2019
KristofferC pushed a commit that referenced this issue Aug 26, 2019
KristofferC pushed a commit that referenced this issue Feb 20, 2020
vchuravy pushed a commit to JuliaLang/Distributed.jl that referenced this issue Oct 6, 2023
vchuravy pushed a commit to JuliaLang/Distributed.jl that referenced this issue Oct 6, 2023
vchuravy pushed a commit to JuliaLang/Distributed.jl that referenced this issue Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parallelism Parallel or distributed computation
Projects
None yet
Development

No branches or pull requests

6 participants