# Migrating from SharedArrays to DistributedArrays

**URL:** <https://discourse.julialang.org/t/migrating-from-sharedarrays-to-distributedarrays/76376>\
**Category:** Julia at Scale\
**Tags:** parallel\
**Created:** [February 13, 2022, 9:52pm UTC](https://discourse.julialang.org/t/migrating-from-sharedarrays-to-distributedarrays/76376 "2022-02-13T21:52:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [February 13, 2022, 9:52pm UTC](https://discourse.julialang.org/t/migrating-from-sharedarrays-to-distributedarrays/76376/1 "2022-02-13T21:52:26Z")

</div>

I have some code that currently works in a shared memory environment with `SharedArrays` structures that I want to migrate to using `DistributedArrays` for a multi-node/distributed memory machine. Roughly, the key part of the code looks like:

```julia
f_vals = SharedArray{Float64}(n_samples);
path_avg = SharedArray{Float64}{n_steps}

@sync @distributed for i in 1:n_samples
  path = generate_path(path_args); # generates a vector of size n_steps
  f_vals[i] = f(path) # apply the scalar value function to this array
  @. path_avg += path/n_samples; # compute the average path
end

```

I would like to compute these same quantities, in roughly the same way, using a for loop with `DistributedArray`, but I haven’t found a good example of how to do this. Also, since the `path_avg` variable is really represents a reduction across all processes, would that remain a `SharedArray`? Note that other than this simple reduction, there is no interaction between the iterates. Thanks for any tips.
