# Distributed Simulations

**URL:** <https://discourse.julialang.org/t/distributed-simulations/49098>\
**Category:** General Usage\
**Created:** [October 27, 2020, 6:41am UTC](https://discourse.julialang.org/t/distributed-simulations/49098 "2020-10-27T06:41:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyacykcharel](https://avatars.discourse-cdn.com/v4/letter/h/58956e/32.png) [@hyacykcharel](https://discourse.julialang.org/u/hyacykcharel)\
**Post date:** [October 27, 2020, 6:41am UTC](https://discourse.julialang.org/t/distributed-simulations/49098/1 "2020-10-27T06:41:36Z")

</div>

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

```julia
using Distributed
addprocs(2)
@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

```

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 2, 2020, 12:04pm UTC](https://discourse.julialang.org/t/distributed-simulations/49098/2 "2020-11-02T12:04:47Z")

</div>

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.  
See [PSA: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)
