朱莉娅酒店

2024-09-27 23:17:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过同步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

Tags: 代码infordist数组synclengthdistributed
1条回答
网友
1楼 · 发布于 2024-09-27 23:17:28

试用

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

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

相关问题 更多 >

    热门问题