# Distributed Simulations

Hello! I’m trying to parallelize this jacobi code but it is not working, can someone help me, please?

``````using Distributed
@everywhere using LinearAlgebra
@everywhere using DistributedArrays
@everywhere  n=5
@everywhere  m=n^2
I=Diagonal(ones(n,n))
A = Tridiagonal([fill(-1, n-2); -1], fill(2, n), [-1; fill(-1, n-2);])
A=kron(A,I)+kron(I,A)
b=ones(m,1)
x=ones(m,1)
d=ones(m,1)
A=distribute(A; dist=(2,1))
b=distribute(b; dist=(2,1))
x=distribute(x; dist=(2,1))
d=distribute(d; dist=(2,1))
@everywhere maxit=10
#@everywhere dx=[]
diagon =Diagonal(A)
@sync begin
for k in 1:maxit
for i in 1:length(localindices[1])
localpart[d][i]=diagon[i,i]
end
dx = (b-A*x)./d
x = x+dx
if norm(dx)< 0.00001
break
end
end
end
x

``````

I don’t know what the algorithm should do, but I see a few stuff that appears to be wrong in the `@sync begin` block. First, I think this block is only running in the master worker, you should use Distributed `pmap`, `@spawn`, etc to make the other workers actually work. Second, I think you are no using properly `localindices` and `localpart`, those are functions and you are trying to index it. Also `diagon`, if is intended to be part of the distributed part of the algorithm, must be defined `@everywhere`. Sorry I can’t help you in more detail, maybe if you isolate the independent issues unrelated of the real specific case, i can do more.