# SharedArray of Measurement type

**URL:** <https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756>\
**Category:** New to Julia\
**Tags:** diffeq, distributed, arrays\
**Created:** [March 9, 2020, 3:24pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756 "2020-03-09T15:24:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hossein\_Haghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hossein_haghi/32/9413_2.png) [@Hossein\_Haghi](https://discourse.julialang.org/u/Hossein_Haghi)\
**Post date:** [March 9, 2020, 3:24pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756/1 "2020-03-09T15:24:05Z")

</div>

I am trying to put the the output (just one data point) of the solution of an ODE that is solved with uncertainty (measrument.jl) multiple times with different initial conditions within a distributed for loop in a SharedArray. I get this error stating

```julia
TaskFailedException:
On worker 2:
MethodError: no method matching Float64(::Measurement{Float64})
Closest candidates are:
  Float64(::Real, !Matched::RoundingMode) where 

```

I believe it does’t like the way that I have initialized my SharedArray which is

```julia
Alpha2 = SharedArray(zeros(100))

```

The main code is pretty long and might be confusing, so here is something very simple with the exact same problem

```julia
using SharedArrays, Distributed, Measurements

A=SharedArray(zeros(10))
@sync @time for i= 1:10
A[i]=i±1
end

```

which after running returns the same error as

```julia
 MethodError: no method matching Float64(::Measurement{Float64})
Closest candidates are:
  Float64(::Real, !Matched::RoundingMode) where T<:AbstractFloat at rounding.jl:200
  Float64(::T) where T<:Number at boot.jl:718
  Float64(!Matched::Int8) at float.jl:60

```

Can someone please point me in the right direction? How should I initialize the SharedArrays so I can put `Measurement{Float64}` inside it within a `@distributed for` loop?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [March 9, 2020, 3:28pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756/2 "2020-03-09T15:28:03Z")

</div>

You need to specify the element type in `zeros` beforehand as `zeros(Measurement{Float64}, 10)`.

---

<div class="post-metadata">

**Author:** ![Hossein\_Haghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hossein_haghi/32/9413_2.png) [@Hossein\_Haghi](https://discourse.julialang.org/u/Hossein_Haghi)\
**Post date:** [March 9, 2020, 3:37pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756/3 "2020-03-09T15:37:35Z")

</div>

> [@simeonschaub](#):
>
> You need to specify the element type in `zeros` beforehand as `zeros(Measurement{Float64}, 10)` .

I changed it to

```julia
using SharedArrays, Distributed, Measurements
A=SharedArray(zeros(Measurement{Float64}, 10))
@sync @time for i= 1:10
A[i]=i±1
end

```

and I get this

```julia
LoadError: ArgumentError: type of SharedArray elements must be bits types, got Measurement{Float64}
in expression starting at untitled-3a064888317d95bbc10641413428b617:2

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 9, 2020, 4:52pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756/4 "2020-03-09T16:52:09Z")

</div>

Measurements types are not isbits so they won’t work with SharedArrays. However, the solution is to just not use SharedArrays: no distributed computing needs it (it’s always faster to just control the transfers yourself), and if you’re not actually doing distributed, then you should probably use multithreading instead.

---

<div class="post-metadata">

**Author:** ![Hossein\_Haghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hossein_haghi/32/9413_2.png) [@Hossein\_Haghi](https://discourse.julialang.org/u/Hossein_Haghi)\
**Post date:** [March 9, 2020, 4:56pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756/5 "2020-03-09T16:56:16Z")

</div>

Thanks, So I have to use `Threads.@threads for` loops

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 9, 2020, 4:56pm UTC](https://discourse.julialang.org/t/sharedarray-of-measurement-type/35756/6 "2020-03-09T16:56:53Z")

</div>

If you’re not using multiple computers together, I would highly recommend it. It’ll have less overhead and will be easier to work with.
