# Shared array for non bit types

**URL:** https://discourse.julialang.org/t/shared-array-for-non-bit-types/81096
**Category:** New to Julia
**Tags:** parallel
**Created:** [May 15, 2022, 1:01pm UTC](https://discourse.julialang.org/t/shared-array-for-non-bit-types/81096 "2022-05-15T13:01:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)
#### Post date: [May 15, 2022, 1:01pm UTC](https://discourse.julialang.org/t/shared-array-for-non-bit-types/81096/1 "2022-05-15T13:01:08Z")

</div>

Probably this is a silly question but I couldn’t find any solution for that.  
I want to iterate over a vector of my own type and do some calculation.  
Here is a MWE

```julia
# julia -p 5
@everywhere mutable struct MyType
    val::Int64
end

function check_move(v::Vector{MyType})
    @sync @distributed for i in 1:length(v)
    # for i in 1:length(v)
        sleep(1)
        v[i].val = 100
    end
end

# initialize the vector of my own type
my_vec = Vector{MyType}(undef,5)
for i in 1:5
    my_vec[i] = MyType(i)
end

# try to change each one of the values to 100
@time check_move(my_vec)
julia> my_vec
# 5-element Vector{MyType}:
# MyType(1)
# MyType(2)
# MyType(3)
# MyType(4)
# MyType(5)

```

But it should be a vector with MyType(100), why does this happen?  
Thanks,  
Elyco

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [May 15, 2022, 3:07pm UTC](https://discourse.julialang.org/t/shared-array-for-non-bit-types/81096/2 "2022-05-15T15:07:18Z")

</div>

You need to use DistributedArrays for this. At the moment you have not done anything here to facilitate interprocess communication.

> **[GitHub - JuliaParallel/DistributedArrays.jl: Distributed Arrays in Julia](https://github.com/JuliaParallel/DistributedArrays.jl)**
>
> Distributed Arrays in Julia. Contribute to JuliaParallel/DistributedArrays.jl development by creating an account on GitHub.

Can you use threads instead? Threads can address the same memory space (e.g. an array) and thus do not need as much communication.
