Parallel processing Julia并行分布 我试图运行这个代码,但是为什么我在中间得到这2行,00000,有人能帮助我,把它固定下来吗?< /P> using Distributed #Bereitstellung der Bibliothekee zur Parallelen Programieru addprocs(2) @everywhere using LinearAlgebra #Bereitstellung der LinearAlgebra Bibliotheke @everywhere using DistributedArrays #Bereitstellung der DistributedArrays @everywhere T =(zeros(n,n)) T[:,1].=10 #Randbedingungen T_links =10 T[:,end].=10 #Randbedingungen T_rechts =10 T = distribute(T; dist=(2,1)) @everywhere maxit = 100 #maximale Iterrationsanzahl @everywhere function Poissons_2D(T) for w in 1:maxit @sync @distributed for p in 1:nworkers() for i in 2:length(localindices(T)[1])-1 for j in 2:length(localindices(T)[2])-1 localpart(T)[i,j] = (1/4 * (localpart(T)[i-1,j] + localpart(T)[i+1,j] + localpart(T)[i,j-1] + localpart(T)[i,j+1])) end end end end return T end Poissons_2D(T) 10×10 DArray{Float64,2,Array{Float64,2}}: 10.0 0.0 0.0 0.0 … 0.0 0.0 0.0 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 5.34146 2.69026 1.40017 1.40017 2.69026 5.34146 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0 10.0 0.0 0.0 0.0 … 0.0 0.0 0.0 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 5.34146 2.69026 1.40017 1.40017 2.69026 5.34146 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0
我认为问题在于I和j的for范围。范围从2到N-1,避免极端情况。这是正确的,因为您缺少计算它们的信息,因为它存储在不同的进程中。但是,您需要传输限制信息。例如,在MPI中,您可以发送冗余信息来避免这种情况,但在分布式环境中,我不确定。我知道原因,但解决办法并不容易。至少我希望能帮点忙。第一次清理可能是这样的:Parallel processing Julia并行分布 我试图运行这个代码,但是为什么我在中间得到这2行,00000,有人能帮助我,把它固定下来吗?< /P> using Distributed #Bereitstellung der Bibliothekee zur Parallelen Programieru addprocs(2) @everywhere using LinearAlgebra #Bereitstellung der LinearAlgebra Bibliotheke @everywhere using DistributedArrays #Bereitstellung der DistributedArrays @everywhere T =(zeros(n,n)) T[:,1].=10 #Randbedingungen T_links =10 T[:,end].=10 #Randbedingungen T_rechts =10 T = distribute(T; dist=(2,1)) @everywhere maxit = 100 #maximale Iterrationsanzahl @everywhere function Poissons_2D(T) for w in 1:maxit @sync @distributed for p in 1:nworkers() for i in 2:length(localindices(T)[1])-1 for j in 2:length(localindices(T)[2])-1 localpart(T)[i,j] = (1/4 * (localpart(T)[i-1,j] + localpart(T)[i+1,j] + localpart(T)[i,j-1] + localpart(T)[i,j+1])) end end end end return T end Poissons_2D(T) 10×10 DArray{Float64,2,Array{Float64,2}}: 10.0 0.0 0.0 0.0 … 0.0 0.0 0.0 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 5.34146 2.69026 1.40017 1.40017 2.69026 5.34146 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0 10.0 0.0 0.0 0.0 … 0.0 0.0 0.0 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 5.34146 2.69026 1.40017 1.40017 2.69026 5.34146 10.0 10.0 4.33779 2.00971 1.01077 1.01077 2.00971 4.33779 10.0 10.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0,parallel-processing,julia,distributed-computing,distributed-algorithm,Parallel Processing,Julia,Distributed Computing,Distributed Algorithm,我认为问题在于I和j的for范围。范围从2到N-1,避免极端情况。这是正确的,因为您缺少计算它们的信息,因为它存储在不同的进程中。但是,您需要传输限制信息。例如,在MPI中,您可以发送冗余信息来避免这种情况,但在分布式环境中,我不确定。我知道原因,但解决办法并不容易。至少我希望能帮点忙。第一次清理可能是这样的: a =(zeros(10,10)) a[:,[1,end]] .= 10 a = distribute(a; dist=(nworkers(),1)) function Poiss
a =(zeros(10,10))
a[:,[1,end]] .= 10
a = distribute(a; dist=(nworkers(),1))
function Poissons_2D(a::DArray, maxit::Int=100)
for w in 1:maxit
@sync @distributed for p in 1:nworkers()
local_a = localpart(a)
local_ind = localindices(a)
for iix in 1:length(local_ind[1])
i = local_ind[1][iix]
(i==1 || i==size(a,1)) && continue
for j in local_ind[2][2:end-1]
local_a[iix,j] = (1/4 * (a[i-1,j] + a[i+1,j] + a[i,j-1] + a[i,j+1]))
end
end
end
end
a
end
一些评论:
- 不要在
前面的任何地方使用@everywhere-您不想在所有工人身上定义它T
- 在Julia中,您按约定使用
来表示参数化类型,因此使用T
,或一些类似于T的符号a
这是全部代码喂!,这正是我想要的,你救了我的命,非常感谢
julia> Poissons_2D(a)
10×10 DArray{Float64,2,Array{Float64,2}}:
10.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0
10.0 4.99998 3.05213 2.20861 1.87565 1.87565 2.20862 3.05214 4.99999 10.0
10.0 6.9478 4.99994 3.90669 3.41834 3.41834 3.9067 4.99995 6.94781 10.0
10.0 7.7913 6.09315 4.99989 4.47269 4.4727 4.99991 6.09317 7.79131 10.0
10.0 8.12425 6.58148 5.52707 4.99987 4.99988 5.52709 6.58151 8.12427 10.0
10.0 8.12425 6.58148 5.52707 4.99987 4.99988 5.52709 6.58151 8.12427 10.0
10.0 7.7913 6.09316 4.99991 4.47271 4.47271 4.99992 6.09317 7.79131 10.0
10.0 6.94781 4.99995 3.90671 3.41835 3.41836 3.90672 4.99996 6.94782 10.0
10.0 4.99999 3.05214 2.20862 1.87566 1.87566 2.20863 3.05215 4.99999 10.0
10.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0