# Bug in DistributedArrays? Pushing to first local part pushes to all local parts

**URL:** <https://discourse.julialang.org/t/bug-in-distributedarrays-pushing-to-first-local-part-pushes-to-all-local-parts/79201>\
**Category:** General Usage\
**Tags:** bug, distributed\
**Created:** [April 8, 2022, 1:20am UTC](https://discourse.julialang.org/t/bug-in-distributedarrays-pushing-to-first-local-part-pushes-to-all-local-parts/79201 "2022-04-08T01:20:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsbryan4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsbryan4/32/34173_2.png) [@jsbryan4](https://discourse.julialang.org/u/jsbryan4)\
**Post date:** [April 8, 2022, 1:20am UTC](https://discourse.julialang.org/t/bug-in-distributedarrays-pushing-to-first-local-part-pushes-to-all-local-parts/79201/1 "2022-04-08T01:20:49Z")

</div>

I found what I believe to be a bug in DistributedArrays. I am trying to push to the first local part of an array but it ends up pushing to all of the local parts.

```julia
using Distributed
addprocs(4)
@everywhere using DistributedArrays

a = dfill([], 10)

s = @spawnat 2 push!(localpart(a)[1], 999)

a

```

I would expect the `a` to be `[[999], [], [], [] ...]`, but it actually is `[[999], [999], [999], [], ...]`. This is unexpected and against my intuition for how it should behave.

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [April 8, 2022, 7:28am UTC](https://discourse.julialang.org/t/bug-in-distributedarrays-pushing-to-first-local-part-pushes-to-all-local-parts/79201/2 "2022-04-08T07:28:54Z")

</div>

This behavior is not specific to `Distributed`, but the way `(d)fill` operates. From the docstring

```julia
If x is an object reference, all elements will refer to the same object:

  julia> A = fill(zeros(2), 2);

  julia> A[1][1] = 42; # modifies both A[1][1] and A[2][1]

  julia> A
  2-element Vector{Vector{Float64}}:
   [42.0, 0.0]
   [42.0, 0.0]
end

```

Create the array locally first and then distribute

```julia
a = distribute([[] for _ in 1:10 ])

```

There is no additional overhead since `dfill` allocates locally first anyway.
