I'm running R on linux box that has 8 multicore processors, and have an optimization problem I'd like to speed up by parallelizing the optimization routine itself. Importantly, this problem involves (1) multiple parameters, and (2) inherently slow model runs. A fairly common problem!
Anyone know of a parallelized optimizer for such occasions?
More specifically, solvers like nlm()
run multiple model evaluations (two per parameter value) each time the algorithm takes a step in parameter space, so parallelizing that instance of multiple model runs would greatly speed things up in these situations when more than a few parameter values are being fit.
It seems like code that makes use of the package parallel
could be written in a way that the user would have to do minimal code modification to move from using nlm()
or optim()
to this parallelized optimization routine. That is, it seems one could rewrite these routines basically with no changes, except that the step of calling the model multiple times, as is common in gradient-based methods, would be done in parallel.
Ideally, something like nlmPara() would take code that looks like
fit <- nlm(MyObjFunc, params0);
and require only minor modifications, e.g.,
fit <- nlmPara(MyObjFunc, params0, ncores=6);
Thoughts/suggestions?
PS: I've taken steps to speed up those model runs, but they're slow for a variety of reasons (i.e. I don't need advice on speeding up the model runs! ;-) ).
Here is a rough solution, that at least has some promise. Big thanks to Ben Bolker for pointing out that many/most optimization routines allow user-specified gradient functions.
A test problem with more parameter values might show more significant improvements, but on an 8 core machine the run using the parallelized gradient function takes about 70% as long as the serial version. Note the crude gradient approximation used here seems to slow convergence and thus adds some time to the process.
I am the author of the R package optimParallel. It provides parallel versions of the gradient-based optimization methods of
optim()
. The main function of the package isoptimParallel()
, which has the same usage and output asoptim()
. UsingoptimParallel()
can significantly reduce optimization times as illustrated in the following figure (p
is the number of paramters).See https://cran.r-project.org/package=optimParallel and http://arxiv.org/abs/1804.11058 for more information.
I used the package doSNOW to run a code on 8 cores. I can just copy&paste the part of the code that refers to this package. Hope it helps!
As you have not accepted an answer, this idea might help: For global optimisation the package
DEoptim()
has an in-built option for parallel optimisation. Nice thing is, it's easy to use and documentation well written.c.f. http://www.jstatsoft.org/v40/i06/paper (currently down)
http://cran.r-project.org/web/packages/DEoptim/index.html
Beware: Differential Evolglobal optimizers might still run into locals.