Question

I am trying to implement code in parallel using Julia. I'm using the @everywhere macro in order to make all processes fetch data from a RemoteRef.

Is it possible to use a variable name thats only defined on the first process in the @everywhere expression and somehow specify that I want it to send the value of that variable, and not the variable name, to all processes?

Example:

r = RemoteRef()
put(r, data)
@everywhere data = fetch(r)

This returns an error because r is not defined on all processes.

How should I move data to all processes?

Also, can I tell Julia to put the value instead of the variable name in the expression? Something akin to how name = "John"; println("Hello, $name") will print "Hello, John"

Was it helpful?

Solution

To find the functions (and macros) Spencer pointed in a nice little package, checkout ParallelDataTransfer.jl. The tests are good examples of usage (and the CI shows that these tests pass on v0.5 on all platforms).

For your problem, you can use the sendto function:

z = randn(10, 10); sendto(workers(), z=z)
@everywhere println(z)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top