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.

 

Reply via email to