This should work, first you need to distribute the top-level variable (data) to all employees:
for pid in workers() remotecall(pid, x->(global data; data=x; nothing), data) end
then do the calculation in chunks using the DArray constructor with some weird indexing:
corrs = DArray((20,20)) do I out=zeros(length(I[1]),length(I[2])) for i=I[1], j=I[2] if i<j out[i-minimum(I[1])+1,j-minimum(I[2])+1]= 0.0 else out[i-minimum(I[1])+1,j-minimum(I[2])+1] = cor(vec(data[i,:]), vec(data[j,:])) end end out end
In more detail, the DArray constructor takes a function that takes a set of indices and returns a piece of the resulting matrix that matches these index ranges. In the above code, I is a set of ranges with I[1] , which is the first range. You can see this more clearly with:
julia> DArray((10,10)) do I println(I) return zeros(length(I[1]),length(I[2])) end From worker 2: (1:10,1:5) From worker 3: (1:10,6:10)
where you can see that he split the array into two parts of the second axis.
The most difficult part of the example was moving from these βglobalβ index ranges to local index ranges by subtracting from the minimum element and then adding 1 back to index on Julia based on 1. Hope this helps!
Jknight
source share