功能
Test
未在远程工作者上定义,您不使用
fetch
因此它无声地失败了。使用
myid()
还需要加载
Distributed
在远程工作人员。最后但并非最不重要的是,远程工作者的标准输出缓存在行级别,因此需要使用
println
而不是
print
.
以下是正确的代码:
using Distributed
@everywhere Distributed
@everywhere function Test()
println("Worker ",myid())
end
for i in workers()
fetch(@spawnat i Test())
end
博古米尔的评论-
取来
在这里,您的代码不会因为其他原因而自动失败。您需要使用@async和@sync宏来收集数据:
jobs = Dict{Int,Future}()
@sync for i in workers()
@async jobs[i] = @spawnat i Test()
end
@sync for i in workers()
@async fetch(jobs[i])
end