I have no authority to speak on this but my impression is this is because
functions are a bit special. Data is pretty straightforward to serialize
and send over the wire, but a generic function in Julia is not just an
ordinary object. Defining functions has global side-effects such as
registering them in the method table so they will be correctly dispatched
on, etc. For this reason, the simplest thing to do if you want to get a
definition over the wire is to just use @everywhere to execute the code
that defines it on another machine.
As for your specific issue, why not just put all your code in a file and
then `include` it on all your processors? For example:
addprocs(4) #<- do this first
@everywhere include("file_that_defines_all_your_functions.jl")
# now do work involving all processors here
On Monday, May 5, 2014 1:15:08 PM UTC-5, Ethan Anderes wrote:
>
> Now I'm having a hard time understanding how variables get passes to and
> from a local worker. In the following, I ask a local worker to to compute
> sin(x) and return the result. Notice that x is defined on the main worker,
> but @spawnat knows to send it's value to the local worker.
>
> addprocs(1)
> x=10
> fetch(@spawnat 2 sin(x))
>
> Why can't the same thing be done with a function?
>
> foo(x) = sin(x)
> fetch(@spawnat 2 foo(x)) #<--- gives an error
>
> Of course, I could get this to work using @everywhere foo(x) = sin(x), but
> for my situation foo depends on a bunch of other functions, which are
> defined before I add the other workers and I don't want to redefine all
> these function with @everywhere once the workers are added.
>
> Any help would be appreciated:)
>
>