Julia ---- 併發編程 @everywhere 和 addprocs 使用順序

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

 

發佈了94 篇原創文章 · 獲贊 74 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章