Multithreading 朱莉娅-工人可以';找不到函数
我目前正在使用Atom编辑器与Julia 0.5一起工作,但不知何故未能使函数对我的工作线程可用。这是我的testfile test.jl:Multithreading 朱莉娅-工人可以';找不到函数,multithreading,julia,Multithreading,Julia,我目前正在使用Atom编辑器与Julia 0.5一起工作,但不知何故未能使函数对我的工作线程可用。这是我的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")
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))
状态:使用DummyModule会导致在所有进程上加载该模块;但是,该模块仅在执行该语句的模块上进入作用域。我再也看不出如何解决这种情况了。我尝试在using行之前添加一个@everywhere,还尝试在它前面添加一个@everywhere include(“test.jl”)
。没有帮助。这应该很简单,但我想不出来
在上,我只找到了,但这并没有真正回答我。如果您自己用
include
导入一个模块,那么您需要告诉julia您想使用该模块中的t1
,方法是在它前面加上testie.t1
试试这个
if nprocs()<2
addprocs(1)
end
@everywhere include("testie.jl")
println(remotecall_fetch(testie.t1,2)) #NB prefix here
非常感谢,这很有效。我不确定自己是否完全理解其中的道理,但现在我知道怎么做了。再次感谢。无论何时使用
include()
if nprocs()<2
addprocs(1)
end
@everywhere include("testie.jl")
println(remotecall_fetch(testie.t1,2)) #NB prefix here
module testie
export t1
function t1()
a= rand()
println("a is $a, thread $(myid())")
return a
end
end