Hi Dominique,
You could do this:
julia> d = dones(10)
10-element DistributedArrays.DArray{Float64,1,Array{Float64,1}}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
julia> @spawnat 2 begin
d_loc = localpart(d)
d_loc[:] += 2
end
RemoteRef(2,1,52)
julia> d
10-element DistributedArrays.DArray{Float64,1,Array{Float64,1}}:
3.0
3.0
3.0
3.0
3.0
1.0
1.0
1.0
1.0
1.0
This type of question has come up often enough that it should probably be
an FAQ (and the documentation of [:] and += expanded).
Cheers!
Kevin
On Sat, Mar 7, 2015 at 12:47 AM, Dominique Orban <[email protected]>
wrote:
> I'd like to modify the chunks of a distributed array in parallel. The
> following bit of code does not modify the distributed array d:
>
> julia> d = dones(10);
> julia>@spawnat 2 begin
> d_loc = localpart(d);
> d_loc = d_loc + 2;
> end
>
> This one does:
>
> julia> @spawnat 2 begin
> d_loc = localpart(d);
> for i = 1 : size(d_loc, 1)
> d_loc[i] = d_loc[i] + 2;
> end
> end
>
> Is there a more convenient syntax that I missed?
>
> Thanks.
>