Parrallel programming

hello im trying to to a parallel compuing but it is not workig can someone please correct this code for me thans?

using Distributed
addprocs(1)
nprocs()
procs()
workers()
nworkers()
@everywhere using DistributedArrays
@everywhere using SharedArrays
@everywhere using LinearAlgebra
using Plots
n=100

@everywhere function Creating_Matrix_A_b(n)
A = dzeros((n-1)^2,(n-1)^2)

#write diagonal block matrices
@distributed (+) for k=1:n-1
    @distributed (+) for l=1:n-1
        A[CartesianIndex.((k-1)*(n-1)+l,(k-1)*(n-1)+l)] .= 4
    end

    @distributed (+) for l=2:n-1
        A[CartesianIndex.((k-1)*(n-1)+l-1,(k-1)*(n-1)+l)] .= -1
        A[CartesianIndex.((k-1)*(n-1)+l,(k-1)*(n-1)+l-1)] .= -1
    end
end

#write upper/lower diagonal block matrices
@distributed (+) for k=2:n-1
    for l=1:n-1
        A[CartesianIndex.((k-2)*(n-1)+l,(k-1)*(n-1)+l)] = -1
        A[CartesianIndex.((k-1)*(n-1)+l,(k-2)*(n-1)+l)] = -1
    end
end

b = 1/n^2 * ones((n-1)^2,1)
return [A,b]

end

(A,b)
#Solve Poisson-equation using dense matrix

#solve linear system
z = A\b

#add boundary values for graphical output
Z = [zeros(1,n+1); [zeros(n-1,1) reshape(z,(n-1,n-1)) zeros(n-1,1)]; zeros(1,n+1)]

##add boundary values for graphical output
#Z=zeros(n+1,n+1);

#for k=1:n-1
#for l=1:n-1
#Z[CartesianIndex.(k+1,l+1)] .= z[(k-1)*(n-1)+l]
#end
#end

#plot result
h = 1.0/n
x = collect(0:h:1)
y = collect(0:h:1)
pyplot()
surface(x,y,Z,)

title!(“Solution of Poisson Equation”)
xlabel!(“x”)
ylabel!(“y”)[quote=“hyacykcharel, post:1, topic:41659, full:true”]

Welcome to the community. You are very unlikely to get help if you post such a large amount of code and with such messy formatting. Try breaking the problem down into smaller pieces and ask for help on a concrete problem. In particular, provide a small code snippet that reproduces the error you get so that people can copy and paste it into their own REPL. See this topic

4 Likes