2
votes

I'm currently using the Atom editor to work with Julia 0.5 and somehow fail to make functions available to my worker threads. Here is my testfile test.jl:

module testie
export t1
  function t1()
    a= rand()
    println("a is $a, thread $(myid())")
    return a
  end
end

if nprocs()<2
  addprocs(1)
end
@everywhere println("Hi")
using testie
t1()
println(remotecall_fetch(t1,2))

Executing this file, I get as output a "Hi" from the master and the worker, and the master will also output the "a is ..." line. But the worker won't, and on the remotecall_fetch line it throws the following error msg (shortened)

LoadError: On worker 2:
UndefVarError: testie not defined

http://docs.julialang.org/en/release-0.5/manual/parallel-computing/ states: using DummyModule causes the module to be loaded on all processes; however, the module is brought into scope only on the one executing the statement. Nothing more I could see how to solve this situation. I tried to add an @everywhere before the using line, also tried to add an @everywhere include("test.jl") right before it. Didn't help. This should be really simple but I can't figure it out.

On SO I only found Julia parallel programming - Making existing function available to all workers but this doesn't really answer it to me.

1

1 Answers

1
votes

If you are importing a module yourself with include then you need to tell julia that you want to use t1 from that module by prefixing it with testie.t1

Try this

if nprocs()<2
  addprocs(1)
end
@everywhere include("testie.jl")
println(remotecall_fetch(testie.t1,2)) #NB prefix here

where testie.jl is:

module testie
export t1
  function t1()
    a= rand()
    println("a is $a, thread $(myid())")
    return a
  end
end