# Using SharedArray with structs

**URL:** <https://discourse.julialang.org/t/using-sharedarray-with-structs/17983>\
**Category:** Julia at Scale\
**Created:** [November 25, 2018, 4:16pm UTC](https://discourse.julialang.org/t/using-sharedarray-with-structs/17983 "2018-11-25T16:16:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HildingElmqvist](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hildingelmqvist/32/6216_2.png) [@HildingElmqvist](https://discourse.julialang.org/u/HildingElmqvist)\
**Post date:** [November 25, 2018, 4:16pm UTC](https://discourse.julialang.org/t/using-sharedarray-with-structs/17983/1 "2018-11-25T16:16:55Z")

</div>

I wanted to use `@distributed for` and `SharedArray{MyStruct,1}`. However, I get the error:

`ArgumentError("type of SharedArray elements must be bits types, got Modia.Instantiation.Instance")`

Is there any other way of returning structs from `distributed for` or other parallelization mechanisms?

---

<div class="post-metadata">

**Author:** ![a-berg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a-berg/32/6218_2.png) [@a-berg](https://discourse.julialang.org/u/a-berg)\
**Post date:** [November 25, 2018, 6:30pm UTC](https://discourse.julialang.org/t/using-sharedarray-with-structs/17983/2 "2018-11-25T18:30:25Z")

</div>

Seems to be expecting [primitive types](https://docs.julialang.org/en/v1/manual/types/index.html#Primitive-Types-1).  
My quick-and-dirty fix would be to make 1 array per field of your struct then map the constructor to the resulting matrices.

```julia
map(MyStruct, array1, array2, ..., arrayN)
# alternative
pmap(MyStruct, array1, array2, ..., arrayN)

```

Then again this is just a silly hack without knowing any of your particular needs.  
As a disclaimer I’m still learning julia, but solving these kind of problems is a great way to improve.
