I'm trying to get my head around parallelization in Julia, but nothing
seems to work as I expect. I've read the Parallel Computing part of the
docs quite a few times, but I'm just not able to apply the principles there
to my problem.
As a simple example, consider the following problem: I have three grids of
values and want to compute the value of a function for each combination of
values on these grids.
grid1 = linspace(1.1, 1.2, 10)
grid2 = linspace(2.1, 2.2, 100)
grid3 = linspace(3.1, 3.3, 100)
results = Array(Float64, (100, 100, 100))
function f(i, j, k, grid1, grid2, grid3)
grid1[i]*grid2[j]*grid3[k]
end
for i = 1:10
for j = 1:100
for k = 1:100
results[i, j, k] = f(i, j, k, grid1, grid2, grid3)
end
end
end
I've tried parallelizing this by using addprocs(3), then defining f using
@everywhere
and turning the array holding the results into a distributed array using
distribute(results). Then I do
@parallel for k=1:100
results[i, j, k] = f(i, j, k, grid1, grid2, grid3)
end
for the inner part of the loop. Still, I find that the results of the
calculations are not sent to be stored in a distributed array. How do I get
the results out of a parallel for loop?