Hello, I’m trying to update some code that was working on julia v0.6 with a global inner function.
Below is the basic idea of what worked in julia 0.6.
In my case (I read image data and process it in the remote) its a bit more complicated with pointers to c objects, so I don’t actually return the variable, but write into a shared array.
When i first wrote the code, I couldn’t get the variable to work as expected as a global, so I made function calls to it. The loop basically runs until stopped by the user.
Edit: I got it working with global variables.
I would still like to know what the recommended way to do something like this is.
#using Distributed
workers()[1] == 1 && addprocs(1)
@everywhere function remoteLoop()
a = 1
#return something
global function somegetter()
println("retruning a: ", a)
return a
end
#change something
global function somesetter()
println("resetting a")
a = 1
return 0
end
# someething that takes a long time
while a < 10
println("remote loop: ", a)
sleep(1)
a += 1
end
return 0
end
#runs on worker 1
trrLoop = @async begin
rrLoopFuture = @spawnat 2 remoteLoop()
r = fetch(rrLoopFuture)
println("remoteLoop finished with $(r)")
end
fetch( @spawnat 2 somegetter())
fetch( @spawnat 2 somesetter())