我想用julia' pmap
来做这样的事情:
pmap( f, v, inits[i])
其中f
是我要在v
上并行调用的函数,这是一个数组。我还想将一些参数传递给f
(inits
),但inits
本身就是一个数组,我希望将ith参数传递给正确的进程。这有意义吗?
我可以通过排序“滚动我自己的' pmap的版本,因为可以使用remotecall_fetch
轻松完成。如果上述情况令人困惑,那么这就是实施:
i=1
nextidx() = (idx=i; i+=1; idx)
@sync begin
for k in 1:np
if k != myid() || np == 1
@async begin
while true
idx = nextidx()
if idx > chains
break
end
result[idx] = remotecall_fetch(k, mcmc_sub, m, iters, burnin,
thin, idx, ps[idx], p)
end
end
end
end
end
答案 0 :(得分:1)
假设您要在v
上运行一些输入pmap
。 v
的每个元素也有一个相关的inits向量,它存储在矩阵inits
的列中。
inits = reshape(randn(20), 5,4)
v = collect(1:4)
关键是要编写你的函数来输入你输入和你的内容的元组
f = function(args::Tuple{Int64, Vector{Float64}})
x, inits = args
return sum(x * inits)
end
然后将输入和输入拉链在一起
args = collect(zip(v, [inits[:,j] for j in 1:4]))
pmap(f, args)