Julia ---- 并发编程 @everywhere 和 addprocs 使用顺序

孤街浪徒 提交于 2020-02-05 21:45:52

addprocs 必须是在 @everywhere 的前面,其他一些并行计算的宏也一样,比如 @async 等。

 

nprocess = 5
addprocs(nprocess)
responses = Vector{Any}(nworkers())

@everywhere function test(x)
    return x * 2.0
end

for i in 1:nworkers()
    responses[i] = remotecall(test, i+1, i)
end

for res in responses
    wait(res)
end

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!