Allocation of distributed arrays to workers

By default when creating a distributed array each worker is assigned consecutive fields.

So for a 10 element array, worker 1 would control 1:5 and worker 2 6:10.

¿Is there a way of defining the DArrays in a way that worker 1 takes care of the odd elements and worker 2 of the even elements?

Thank you!

You can do this with SharedArrays:

julia> using Distributed
julia> addprocs(2)
julia> @everywhere using SharedArrays
julia> S = SharedArray{Int,1}(10, init = S -> S[indexpids(S):2:length(S)] = repeat([myid()], length(indexpids(S):2:length(S))))
10-element SharedArray{Int64,1}:
 2
 3
 2
 3
 2
 3
 2
 3
 2
 3

In other words, you can have each worker access particular elements based on their id (returned by myid())

I would rather use DistributedArrays due to performance, SharedArrays make a copy to hard disk, while DistributedArrays work from memory.

Really? If you don’t create a SharedArray backed by a file (via SharedArray(file, type, dims) ), then I don’t see why the disk would be used. I’ve had good results with SharedArrays, in my limited experience.

In any case the question might be pertinent for HPC environments where users aren’t using shared memory

Idiot reply from me. Is there a way to reshape the original array such that the even and odd elements appear to be contiguous columns?

I guess I am asking this in a blue sky fashion in general for arrays, which might be interesting.