Consider the following code:
module Foo using Distributed remote_work(i) = Distributed.remotecall_fetch(()->1+i, 2) end using Distributed addprocs(1) Foo.remote_work(1) # errors
The last line errors with,
ERROR: On worker 2: UndefVarError: Foo not defined deserialize_module at /home/marius/src/julia-1.4/usr/share/julia/stdlib/v1.4/Serialization/src/Serialization.jl:915 ...
presumably because module
Foo is (intentionally) not defined on the worker. However, obviously nothing in
()->1+i actually depends on
Foo, so it seems like it could run, its just that somewhere in that closure (maybe a line number or some other hidden metadata?) there’s a reference to
Foo. So is there a way to get this to run on a remote worker anyway?
One obvious solution is to eval the closure in Main which works in stripping out any references to
Foo which may have been there:
remote_work(i) = Distributed.remotecall_fetch(@eval(Main,()->1+$i), 2)
but in my real case it becomes too onerous to track down all the variables like
$i that need to be interpolated, so I’m hoping there’s another (even if hacky) solution. Any ideas? Thanks.