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

module globals and parallel methods #19

Open
amitmurthy opened this issue Dec 2, 2014 · 4 comments
Open

module globals and parallel methods #19

amitmurthy opened this issue Dec 2, 2014 · 4 comments

Comments

@amitmurthy
Copy link
Contributor

Consider the following:

julia> addprocs(1)
1-element Array{Int64,1}:
 2

julia> @everywhere module Foo

       foo() = remotecall(2, ()->(global X=[1]))
       bar() = @everywhere X[1]=2

       end

julia> Foo.foo()
RemoteRef(2,1,6)

julia> Foo.bar()
exception on 1: exception on 2: ERROR: X not defined
 in eval at /home/amitm/Work/julia/julia/base/sysimg.jl:7
 in anonymous at multi.jl:1439
 in run_work_thunk at multi.jl:598
 in run_work_thunk at multi.jl:607
 in anonymous at task.jl:6

This is because foo() creates X as module global, while the @everywhere call refers to Main

Would it be appropriate to have the remote part of all parallel methods execute under the same module as the calling module? Is information about the calling module available to a function in Base?

@ArchRobison
Copy link

Thinking about this revealed how fuzzy I am on the module system. Modules seem to be objects. For example, a==b works for two modules a and b. But if I have two modules in different processes, what makes them the "same"? The path of names to reach them? Also, just for serial code, is there a way to "inject" evaluation of an expression into a module, or is that a meaningless question?

@toivoh
Copy link

toivoh commented Dec 11, 2014

For the second question: I belive that eval(MyModule, expr) should work, maybe also MyModule.eval(expr).

@malmaud
Copy link

malmaud commented Oct 14, 2015

@ArchRobison The only built-in notion of 'sameness' for modules is if the two module instances are "==="; ie have the same memory address. Each invocation of module X ... end will create a new module object, so module equality has nothing to do with the name of the module.

@malmaud
Copy link

malmaud commented Oct 16, 2015

Related:

julia> module M
       x=1
       y=@fetch x+1
       end
WARNING: Module M not defined on process 2
fatal error on 2: ERROR: UndefVarError: M not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants