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

Nested anonymous functions not propagating to workers #15451

Closed
ivirshup opened this issue Mar 11, 2016 · 3 comments
Closed

Nested anonymous functions not propagating to workers #15451

ivirshup opened this issue Mar 11, 2016 · 3 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior parallelism Parallel or distributed computation regression Regression in behavior compared to a previous version
Milestone

Comments

@ivirshup
Copy link
Contributor

Hi,

I think I've found a bug? Nested anonymous function aren't propagating to workers with @everywhere:

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

julia> @everywhere f = (x->(y->y+1)(x) + 1)

julia> remotecall_fetch(f, 2, 1)
ERROR: On worker 2:
UndefVarError: 6#8 not defined
 in #5 at ./none:1
 in run_work_thunk at ./multi.jl:722
 [inlined code] from ./multi.jl:1018
 in #253 at ./task.jl:59
 in remotecall_fetch(::Any, ::Base.Worker, ::Int64, ::Vararg{Int64}) at ./multi.jl:808
 in remotecall_fetch(::Any, ::Int64, ::Int64, ::Vararg{Int64}) at ./multi.jl:811
 in eval(::Module, ::Any) at ./boot.jl:267

julia> versioninfo()
Julia Version 0.5.0-dev+3050
Commit c96f322 (2016-03-08 04:08 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.3.0)
  CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1

Update:

I've found a more general example:

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

julia> remotecall_fetch((x->(y->y)(x)), 2, 1)
ERROR: On worker 2:
UndefVarError: 2#4 not defined
 in #1 at ./none:1
 in run_work_thunk at ./multi.jl:744
 [inlined code] from ./multi.jl:1040
 in #255 at ./task.jl:59
 in remotecall_fetch(::Any, ::Base.Worker, ::Int64, ::Vararg{Int64}) at ./multi.jl:830
 in remotecall_fetch(::Any, ::Int64, ::Int64, ::Vararg{Int64}) at ./multi.jl:833
 in eval(::Module, ::Any) at ./boot.jl:267
@ivirshup ivirshup changed the title Nested anonymous functions not propagating with @everywhere Nested anonymous functions not propagating to workers Mar 11, 2016
@jrevels jrevels added the parallelism Parallel or distributed computation label Mar 11, 2016
@amitmurthy
Copy link
Contributor

The following work:

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

julia> remotecall_fetch(x->f(1), 2, 1)
3

It appears that f is indeed defined on all workers. In the case of remotecall_fetch(f, 2, 1) while one would expect only the symbol and module to be serialized, it is actually serializing the locally defined function.

cc: @JeffBezanson

@ivirshup
Copy link
Contributor Author

ivirshup commented Apr 27, 2016

Came across another (probably more common) case:

pmap([rand(2) for i in 1:2]) do x
    map(y->typeof(y), x)
end

This generates a pretty long error report so I've put an example of running it here.

edit: corrected code.

@amitmurthy amitmurthy added this to the 0.5.0 milestone Apr 29, 2016
@JeffBezanson JeffBezanson added bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version labels May 13, 2016
@JeffBezanson
Copy link
Member

The issue here is that nested functions now generate multiple top-level functions. So the immediate function you're trying to send refers to globals in Main that are not being sent.

I think the right solution is to look through the IR for the function when it's serialized, and send over all its dependencies. This could also potentially let us remove the localize_vars hack. We can also keep track of which items from Main we've sent to which processors and avoid re-sending, which would be a helpful optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior parallelism Parallel or distributed computation regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

4 participants