SharedArray of composite types

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

1 Like
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)

4 Likes

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?

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.

3 Likes

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

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

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