SharedArray of composite types


#1

I would like to be able to construct a SharedArray-like object of composite types. It says in the documentation that the shared array must be of a bits type. What is the best way of going about this?

Thanks


#2
julia> struct Foo
           a::Int
           b::Float64
       end

julia> isbits(Foo)
true

julia> SharedArray{Foo, 1}((10,))
10-element SharedArray{Foo,1}:
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)
 Foo(0, 0.0)


#3

Thanks for the response. My type is not a bits type, and this throws an error. Any idea how I could get this to work?


#4

You just can’t use SharedArray then. You could think about switching to using @threads (shared-memory threads) instead of @parallel.

Edit: that or use @spawn, remotecall, etc.


#5

Thanks for the help. I’ll explore the options you’ve suggested.


#6

Use a bitstype instead. What is preventing it from being a bitstype? Eg. Replace arrays with tuples.


#7

Thanks for the suggestion - I might try that in the future. Using @threads, as suggested by @tkoolen, is working well for me.