# Right way of using DistributedArrays

**URL:** <https://discourse.julialang.org/t/right-way-of-using-distributedarrays/4657>\
**Category:** General Usage\
**Created:** [July 5, 2017, 7:16am UTC](https://discourse.julialang.org/t/right-way-of-using-distributedarrays/4657 "2017-07-05T07:16:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [July 5, 2017, 7:16am UTC](https://discourse.julialang.org/t/right-way-of-using-distributedarrays/4657/1 "2017-07-05T07:16:42Z")

</div>

Hi,

I want to apply an inplace function `foo!` to a vector of elements of type `lT`. I want this operation to be done in parallel (distributed) because this vector is big. Is the following prototype the right way to do it?

Thank you for your advices for simplifying / improving it.

Best,

```julia
addprocs(3)
@everywhere importall DistributedArrays
@everywhere importall DistributedArrays.SPMD
@everywhere struct lT
  a::Vector{Float64}
  ii::Int64
end

dA=@DArray [lT(zeros(rand(3:10)),i) for i=1:200]

for p=procs(dA) @spawnat p println(size(localpart(dA))) end

@everywhere function foo!(v::Vector{Float64},k)
  v .+= k
end

@everywhere function foo_spmd(d_in, d_out)
  mylp = d_in[:L]
  for t in mylp
    println("$(myid()) -- $(t.ii)")
    foo!(t.a,t.ii)
  end
end

spmd(foo_spmd, dA, dA)

```
