Parallel processing 如何与Julia语言并行运行函数?

Parallel processing 如何与Julia语言并行运行函数?,parallel-processing,julia,Parallel Processing,Julia,我正试图找出如何与Julia一起使用并行计算。文档看起来很棒,即使对于像我这样从未使用过并行计算(并且不理解文档背后的大多数概念;)的人来说也是如此 我要说的是:我在一台装有Ubuntu的电脑上工作。它有一个4核处理器 为了运行下面描述的代码,我将julia终端称为: $ julia -p 4 我正在跟踪文档。我在中描述的示例中遇到了一些问题 我正在尝试运行以下代码: @everywhere advection_shared_chunk!(q, u) = advection_chunk!(q,

我正试图找出如何与Julia一起使用并行计算。文档看起来很棒,即使对于像我这样从未使用过并行计算(并且不理解文档背后的大多数概念;)的人来说也是如此

我要说的是:我在一台装有Ubuntu的电脑上工作。它有一个4核处理器

为了运行下面描述的代码,我将julia终端称为:

$ julia -p 4
我正在跟踪文档。我在中描述的示例中遇到了一些问题

我正在尝试运行以下代码:

@everywhere advection_shared_chunk!(q, u) = advection_chunk!(q, u, myrange(q)..., 1:size(q,3)-1)

function advection_shared!(q, u)
    @sync begin
        for p in procs(q)
            @async remotecall_wait(advection_shared_chunk!, p, q, u)
        end
    end
    q
end

q = SharedArray(Float64, (500,500,500))
u = SharedArray(Float64, (500,500,500))

#Run once to JIT-compile
advection_shared!(q,u)
但我面临以下错误:

ERROR: MethodError: `remotecall_wait` has no method matching remotecall_wait(::Function, ::Int64, ::SharedArray{Float64,3}, ::SharedArray{Float64,3})
Closest candidates are:
  remotecall_wait(::LocalProcess, ::Any, ::Any...)
  remotecall_wait(::Base.Worker, ::Any, ::Any...)
  remotecall_wait(::Integer, ::Any, ::Any...)
 in anonymous at task.jl:447

...and 3 other exceptions.

 in sync_end at ./task.jl:413
 [inlined code] from task.jl:422
 in advection_shared! at none:2
我做错了什么?据我所知,我只是在复制文档中的示例。。。还是不

谢谢你的帮助


谢谢@Daniel Arndt,你找到窍门了!我在查看中的文档:我以为它应该是相对于Julia 0.4.x(到目前为止最新的稳定版本)的文档,但它似乎是相对于Julia 0.5.x(所有版本中最新的版本)的文档

我做了你建议的更改(更改了顺序并添加了缺少的功能),一切都很顺利。我将把更新后的代码留在这里

# Here's the kernel
@everywhere function advection_chunk!(q, u, irange, jrange, trange)
    @show (irange, jrange, trange)  # display so we can see what's happening
    for t in trange, j in jrange, i in irange
        q[i,j,t+1] = q[i,j,t] +  u[i,j,t]
    end
    q
end

# This function retuns the (irange,jrange) indexes assigned to this worker
@everywhere function myrange(q::SharedArray)
    idx = indexpids(q)
    if idx == 0
        # This worker is not assigned a piece
        return 1:0, 1:0
    end
    nchunks = length(procs(q))
    splits = [round(Int, s) for s in linspace(0,size(q,2),nchunks+1)]
    1:size(q,1), splits[idx]+1:splits[idx+1]
end

@everywhere advection_shared_chunk!(q, u) = advection_chunk!(q, u, myrange(q)..., 1:size(q,3)-1)

function advection_shared!(q, u)
    @sync begin
        for p in procs(q)
            @async remotecall_wait(p, advection_shared_chunk!, q, u)
        end
    end
    q
end

q = SharedArray(Float64, (500,500,500))
u = SharedArray(Float64, (500,500,500))

#Run once to JIT-compile
advection_shared!(q,u)

完成了

我不认为你做错了什么,除了你可能正在使用更新版本的文档(或者我们看到了不同的东西!)

让我们确保您正在使用Julia 0.4.x和以下文档:

在Julia v0.5.0中,
remotecall\u wait
的前两个参数的顺序已更改。将顺序切换到
remotecall\u wait(p,advection\u shared\u chunk!,q,u)
,您应该会看到下一个错误(
myrange
未定义,可以在前面的文档中找到)