In section title What are the possible causes of an UndefVarError during remote execution? in page 427 Julia 1.3.0 doc pdf, there is the following code example:
@everywhere module Foo
function foo()
global gvar = "Hello"
remotecall_fetch(() -> gvar, 2)
end
end
To fix the intentional bug and make the code work, I had to introduces two fixes:
@everywhere module Foo
using Distributed
gvar = "Hello"
function foo()
remotecall_fetch(() -> gvar, 2)
end
end
-
using Distributedadded to the moduleFoo -
gvaris put in module global from the beginning
Here I wonder why using Distributed had to be added to the module Foo because I already ran using Distributed outside of module Foo before I do @everywhere module Foo, thereby having made the remote processes ready for using Distributed far before Foo was defined.