I have been struggling with this issue as well. Unfortunately, Julia does 
not have shared memory parallelisation (yet 
<https://github.com/JuliaLang/julia/issues/1790>), so there is no 'nice' 
solution for this.
You could of course construct your function like

@everywhere f(x,r) = sum(x./r,2)

But, if you don't want to pass the array r every time you call the 
function, you can write a separate file, say myFile.jl that contains

r = collect(1:100)
f(x) = sum(x./r)

Next, include the file on all processors, like

@everywhere include("myFile.jl")

then you can do

a = ones(100)
r = @spawnat 2 f(a)
fetch(r)

which gives 5.187378 as result. Unfortunately, this means that every 
processor will contain its own copy of the array r, which does not make 
sense if you are running your code on a multicore machine with only one 
physical memory. Luckily, there is something like Shared Arrays 
<http://docs.julialang.org/en/latest/stdlib/parallel/#Base.SharedArray> for 
this. 

Reply via email to