[英]DistributedArrays Julia
I'm trying to run this code in parallel by synchronizing the local Part of the DistributedArrays so that only the first line of the Arrays of the first process is 200 and not the first row of the second Array, can someone help, please?我正在尝试通过同步 DistributedArrays 的本地部分来并行运行此代码,以便第一个进程的 Arrays 的第一行是 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
Try using尝试使用
if DistributedArrays.localpartindex(Z) == 1; localpart(Z)[1,:].=200;end
Moreover, you should not nest @distributed
loop.此外,您不应该嵌套
@distributed
循环。 Rather make it with one parameter eg.而是用一个参数来制作它,例如。
xi
in such a way that the values of x
and i
are calculated on the base of xi
xi
使得x
和i
的值基于xi
计算
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.