I am trying to learn parallel computing in Julia. I want to send something to every processes, but keep other things only at the main process. I had the following weird error.
My sample code is (for simplicity):
using Distributed
addprocs(3) # my computer has two cores four threads, so add extra 3 processes
@everywhere using Distributions
@everywhere N = 3 # this variable N should be in all processes
# for the following two lines, I only need them to be in the main process
push!(LOAD_PATH,"pwd()")
using MyModule # this is a module I created
When I run my code in Atom, I got the following error:
On worker 2:
ArgumentError: Package fake_data_simple_matching [top-level] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
However, if I re-evaluate the last two lines, it does not report an error. I couldn’t find out the reason. I thought that if I do not add @everywhere
, then the last two lines should automatically be evaluated by the main process.
I have another question. As a continuation of my code, I have
temp = MyModule.foo() # foo is a function in the module
I want to put temp
on every processes. I understand that adding @everywhere
before temp
will not work because the module is only defined on the main process. So what function should I use to send temp
to every process? Should I code as
@spawnat :any temp