繁体   English   中英

分布式阵列 Julia

[英]DistributedArrays Julia

我正在尝试通过同步 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

尝试使用

if DistributedArrays.localpartindex(Z) == 1; localpart(Z)[1,:].=200;end

此外,您不应该嵌套@distributed循环。 而是用一个参数来制作它,例如。 xi使得xi的值基于xi计算

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM