Right way of using DistributedArrays


#1

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,

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)