Po C.
Po C.

Reputation: 688

Shared Array with more complicated element type

A simplified example:

nsize = 100
vsize = 10000
varray = [rand(vsize) for i in 1:nsize] #say, I have a set of vectors.

for k in 1:nsize
    varray[k] = rand(vsize, vsize) * varray[k]
end

Obviously, the above for loop can be parallelized.

According to Parallel Map and Loops in Julia manual, I need to used SharedArray. However, ShardArray cannot have Array{Float64,1} as element type.

julia> a = SharedArray(Array{Float64,1}, nsize)
ERROR: ArgumentError: type of SharedArray elements must be bits types, got Array{Float64,1}
 in __SharedArray#138__ at sharedarray.jl:45
 in SharedArray at sharedarray.jl:116

How can I solve this problem?

Upvotes: 2

Views: 610

Answers (1)

tholy
tholy

Reputation: 12179

Currently, you can't, because a SharedArray requires a contiguous block of memory, which means that its elements must be "bits types," and this isn't true for Array. (Array is implemented in C and has some header information, which makes them not densely-packable.)

However, if all of your "element" arrays have the same size, and you don't absolutely require the ability to modify single elements of the "inner" arrays, you could try using StaticArrays as elements. (Thanks to @Wouter in the comments below for pointing out that this needed updating.)

Upvotes: 4

Related Questions