Others know much more about this area than I do, so hopefully they'll chime in 
and correct anything I say that's wrong.

@spawnat (and similar functions) "localize" variables on remote workers by 
effectively wrapping them in let blocks. That means that when the command 
finishes, the (new) a goes out of scope.

You can achieve what you seem to want this way:

    remotecall(2, ()->eval(Main,:(a=5)))

See how the @everywhere macro is defined (in base/multi.jl). You could define a 
similar @somewhere (or something) that allows you to evaluate the expression 
on a specified process.

But I suspect you can also use RemoteRefs as variables, in which case this 
issue presumably won't come up. There's a small illustration of this technique 
in the Parallel Computing section of the manual _if_ you select "latest". 
(Perhaps that change should be backported to 0.3.)

--Tim

On Thursday, October 30, 2014 11:13:07 AM Kanu Sahai wrote:
> Hello
> 
> I am a beginner in Julia and have been trying to build an application in
> it. Although, I am facing a conceptual doubt.
> 
> I am working with 4 worker processes on one node.
> 
> > addprocs(4)
> 
> I define a variable 'a' on all the processes.
> 
> julia> @everywhere a=4
> 
> Next, I try to modify the value of 'a' at worker#2
> 
> julia> @spawnat 2 a=5
> RemoteRef(2,1,16)
> 
> julia> fetch(ans)
> 5
> 
> Now, if I print the value of 'a' at all processors, I get :
> 
> julia> @everywhere println(a)
> 4
>     From worker 2:    4
>     From worker 4:    4
>     From worker 5:    4
>     From worker 3:    4
> 
> Why is the modified value of 'a' not reflected here ? Am I missing
> something in the logic ?
> 
> Thanks so much!

Reply via email to