Julia supports parallelization using methods such as pmat () and @parallel.
I am trying to calculate the dissimilarity matrix for a dataset:
n = length(dataset) mat = zeros(n,n) for i = 1 : n for j = i+1 : n mat[i,j] = mat[j,i] = f_dist(dataset[i], dataset[j]) end end
Since the calculations are independent, I believe this is a good candidate for parallel computing.
My attempt to use pmat () and @parallel both ended more slowly.
mat = @parallel (+) for comb in collect(combinations([1:n],2)) submat = zeros(n,n) i = comb[1] j = comb[2] dist = f_dist(dataset[i],dataset[j]) submat[i,j] = dist submat[j,i] = dist submat end
I understand that @parallel is a bad way to go because I essentially create a bunch of sparse matrices and add them together. Very inefficient.
Is there an effective way to make this work? I tried SharedArrays and DistributedArrays, but didn't understand how to do what I want.
Thanks.
source share