# Explicit distribution of chunks in SharedArray?

**URL:** <https://discourse.julialang.org/t/explicit-distribution-of-chunks-in-sharedarray/53249>\
**Category:** Performance\
**Tags:** question, sharedarrays\
**Created:** [January 12, 2021, 7:30pm UTC](https://discourse.julialang.org/t/explicit-distribution-of-chunks-in-sharedarray/53249 "2021-01-12T19:30:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [January 12, 2021, 7:30pm UTC](https://discourse.julialang.org/t/explicit-distribution-of-chunks-in-sharedarray/53249/1 "2021-01-12T19:30:02Z")

</div>

How can I construct a SharedArray with a specific chunk distribution across workers?  
For instance:

```julia
julia -p 2
using SharedArrays,Distributed,Test
@everywhere using SharedArrays

a = SharedArray{Float64,2}((3,5),init = x-> ... )
@test @fetchfrom 2 localindices(a) == 1:6
@test @fetchfrom 2 localindices(a) == 7:15

```

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [January 12, 2021, 8:11pm UTC](https://discourse.julialang.org/t/explicit-distribution-of-chunks-in-sharedarray/53249/2 "2021-01-12T20:11:40Z")

</div>

Hey! If you read the help for `localindices` you can see that it is just a convenience function. You can distribute the work as you wish, unconstrained by `localindices`. The memory is shared by all the workers (for read/write purposes).

So you can do things like `@fetchfrom 2 a[8] = myid()`. Though 8 is not a “localindex” on 2.

If you want more control over distribution and ownership of memory, check out `DistributedArrays.jl`.

Cheers!

---

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [January 12, 2021, 8:23pm UTC](https://discourse.julialang.org/t/explicit-distribution-of-chunks-in-sharedarray/53249/3 "2021-01-12T20:23:24Z")

</div>

awesome, thanks
