【发布时间】:2021-02-08 03:13:00
【问题描述】:
我正在尝试通过同步 DistributedArrays 的本地部分来并行运行此代码,以便只有第一个进程的数组的第一行是 200 而不是第二个数组的第一行,有人可以帮忙吗,请问?
using Distributed
addprocs(2)
@everywhere using DistributedArrays
@everywhere using LinearAlgebra
n=10
Z=zeros(n,n)
#Z[1,:].=200
#Z[:,end].=200
Z=distribute(Z; dist=(2,1))
K=ones(n,1)
#K[1,:].=200
#K[end,:].=200
K=distribute(K; dist=(2,1))
#(i+1) % 2)+1,j
@sync @distributed for x in 1:nworkers()
localpart(Z)[1,:].=200
@sync @distributed for i in 2:length(localindices(Z)[1])
for j in 1:length(localindices(Z)[2])
localpart(Z)[i,j]=10*log(myid())+localpart(K)[i]
end
end
end
end
Z
【问题讨论】:
-
我不明白你想做什么。你能不能展示一个工作的非分布式版本,然后尝试并行化它?
-
我已经有了它的正常版本,现在我试图将代码瘫痪在工人身上,这是正常工作的正常版本。
-
看看SharedArrays,它们可能更适合你想要做的事情
-
SharedArrays 不会工作,因为我正在使用 Raspberry Cluster
标签: python performance parallel-processing julia distributed