After succesfully parallelizing a larger number of small tasks using the 
@sync @parallel approach and SharedArrays, I'm currently stumped trying to 
parallelize a small number of large tasks. 
I'm basically trying to compare the results of minimization procedures 
using different NLopt algorithms, where each minimization takes at least 15 
minutes to finish. The function 

function min_func(inputs::Array, global::Symbol, local::Symbol)
  ...
end

I then have all possible combinations of global and local methods in a 
2-dimensional array, and my first attempt at parallelization was:

results = SharedArray(Float64, (length(methods), dimension+1))

@sync @parallel for i = 1:length(methods)
  (f, x, flag) = min_func(inputs, methods[i,1], methods[i,2])
  results[i,1] = f
  results[i,2:end] = x
end

This is basically a one-to-one translation of the approach I had 
succesfully taken when implementing the aforementioned problem with lots of 
small computations. However, here it seems that there's nothing actually 
happening in parallel, as my CPU load indicates only one process is 
actually working. I don't understand why the other i's are not executed in 
parallel on the remaining workers?

Now the parallel documentation suggests that for large tasks, pmap would be 
the better approach, but I can't get it to go. If I understand correctly, 
the idea would be to call 

pmap(min_func, inputs, methods[:,1], methods[:,2])

which would then automatically call min_func with (methods[1,1], 
methods[1,2]), (methods[2,1], methods[2,2]), and so on, returning a vector 
of length(methods), with a tuple (f,x,flag) in each cell. The problem with 
this approach is that I can't (or at least don't know how to properly) pass 
the input array to the function, as pmap will then try to call the function 
for (inputs[1], methods[1,1], methods[1,2]) and so on, when actually inputs 
has to be passed as an Array. Is there a syntax for passing additional 
arguments to functions in pmap or do I have to rewrite my function so that 
it only takes the elements of the list pmap is iterating over as inputs?

Reply via email to