8
votes

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"

1
Still have an issue with this? I'm sure you can do what you want, but there are multiple questions and I'm not sure which/how to address them. - rickhg12hs
I think I've found a solution by making the data an argument of a function that I can @spawnat various processes, but its not a great solution. Any help would be much appreciated. What do I need to tell you? - stords
That's great you see how the data can be made an argument for a @spawnat. If it's okay to replicate your data everywhere, there are other options ... and if you're on Linux, you can use SharedArray too. Need to keep data movement to a minimum to be efficient. Maybe if you wrote a bit about your "big picture", the parallelization options might be a bit clearer. - rickhg12hs
Im trying to make a parallel restricted boltzman machine. Each process owns a portion of the training examples. I want to send every process the matrix of weights, allow them to determine an update to the weights based on their training examples, and send that update back to the main process. The main process then calculates the new weights matrix and sends it back to all the other processes so they can train again. - stords
I just answered a related question here I think the functions I posted should help you do what you need to. - spencerlyon2

1 Answers

0
votes

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)