I suspect that global variable is what Eka is after here. If you put "global" in front of the definition of d, it will work. I would advise against using globals, however. It's much better to return the array and pass it to the other function as an argument.
> On May 28, 2014, at 5:24 PM, Jameson Nash <[email protected]> wrote: > > A RemoteRef lets up pass around a variable without actually moving the data > (until you fetch) > > On Wednesday, May 28, 2014, Eka Palamadai <[email protected]> wrote: >> Is it possible to persist a variable across function calls? >> >> Consider 2 functions foo and bar shown below : >> ----------------------------- >> function foo() >> d = zeros(5) >> for i = 1:5 >> d [i] = i >> end >> end >> >> function bar() >> println ("d", d) >> end >> >> function test_parallel() >> @spawnat 2 foo() >> @spawnat 2 bar() >> end >> ----------------------------- >> The code doesn't compile since d is not defined in function bar. >> >> foo defines array d but bar needs to use d as well. >> >> How could both foo and bar use d without passing d around? >> >> I could pass d back and forth, but i would like to avoid the communication >> overhead. >> Any ideas? >> >> Thanks.
