I'm trying to run this code, but why I'm I getting these 2 rows in the Middle with 00000, can someone help me, to get that fixed, please?
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
The first cleanup could look like this:
Some remarks:
T
- you do not want to define it on all workersT
to denote parametric types so usea
, or some T-like LaTeX symbolHowever, your function takes values from all adjacent cells to calculate new values. I do not know how do you plan to handle situation when the value does not exist yet.
In particular if each row requires value from the previous row and previous column it is not possible to parallelize this computation at all (because you need to wait for the previous value to get the next one).