我试图通过同步DistributedArray的本地部分来并行运行这段代码,以便第一个进程的数组的第一行是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
试用
此外,您不应该嵌套
@distributed
循环。而是使用一个参数,例如xi
,这样x
和i
的值是基于xi
计算的相关问题 更多 >
编程相关推荐