robertfeldt / BlackBoxOptim.jl

Black-box optimization for Julia
Other
439 stars 56 forks source link

Optimization inside multi-threaded loop #129

Open Dom-DC opened 5 years ago

Dom-DC commented 5 years ago

Hi, I've encountered a problem when trying to run BBO inside a threaded loop on my Linux machine running Julia 1.0.1. After starting Julia with multiple threads (and verifying that they're running) I constructed the MWE below. If I remove the "Threads.@threads" part from the code it runs without any issues but once I activate it the code returns all sorts of Errors arising in the threaded loop.

using  BlackBoxOptim

grid=collect(range(1.,5.,length=5)); 
storage=zeros(length(grid));
Threads.@threads for (idx, i_val) in enumerate(grid)

      function rosenbrock2d(x)
        return (1.0 - i_val * x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
      end

    res = BlackBoxOptim.bboptimize(rosenbrock2d, NumDimensions =2);
    storage[idx] = best_candidate(res)[1]
end
jpsamaroo commented 5 years ago

@Dom-DC would you mind showing us what the error backtrace looks like? Additionally, have you tried running this on Julia 1.2 or 1.3/master, where threading is more robust?

robertfeldt commented 4 years ago

Yes, please try this again and in particular using the new multithreading support, see example in file examples/multithreaded_optimization.jl