Skip to content

Instantly share code, notes, and snippets.

@multidis
Created September 29, 2016 21:29
Show Gist options
  • Save multidis/660adbcb2e3b0df2e07436c75b5403a0 to your computer and use it in GitHub Desktop.
Save multidis/660adbcb2e3b0df2e07436c75b5403a0 to your computer and use it in GitHub Desktop.
Timing pmap calls involving Optim.jl in Julia versions 0.4 vs. 0.5. https://github.com/JuliaOpt/Optim.jl/issues/290
## timing pmap with Optim calls inside the function being applied
using Optim
@everywhere foptimtry(fobj::Function) = try
# fminbox local search: conjugate gradient
Optim.optimize(Optim.DifferentiableFunction(fobj), zeros(2), -10*ones(2), 10*ones(2),
Optim.Fminbox();
# outer loop: bounds barrier
iterations = 200,
# inner loop: each optimizer run
optimizer = Optim.ConjugateGradient,
optimizer_o = Optim.OptimizationOptions(iterations = 1_000)
)
catch
# linesearch error
nothing
end
function frunmap(nmap::Int64, nmat::Int64)
M = randn(nmat, nmat)
# global min at (1,1), f(1,1)=0
frosenbrock(x::Array) = (1.0 - x[1])^2 + 100.0*(x[2] - x[1]^2)^2
# closure to parallel-apply
function fmaploc(vi::Int64)
#svd(M)
optres = foptimtry(frosenbrock)
if optres == nothing
return nothing
else
return optres.f_minimum
end
end
return pmap(fmaploc, collect(1:nmap))
end
Ntimes = 3
Nmatsize = 1_000
@time println(frunmap(Ntimes, Nmatsize))
@time frunmap(Ntimes, Nmatsize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment