Hi,
Can anyone help me to parallelize the following code? I’ve tried to look for how to parallelize nested loops in the documentation but I couldn’t find anything about it.
Thank you,
using Optim
s_vals = collect(range(0.5,1.5,length=10))
k_vals = collect(range(50.0,150.0,length=10))
function obj(x,s,k)
return (s - x[1])^2 + k * (x[2] - x[1]^2)^2
end
sol = zeros(Float64, 2, length(k_vals), length(s_vals))
for (i_s, s) in enumerate(s_vals), (i_k, k) in enumerate(k_vals)
obj!(x) = obj(x,s,k)
res = optimize(obj!, zeros(2), Optim.BFGS())
sol[1, i_k, i_s], sol[2, i_k, i_s] = res.minimizer
end