Reputation: 43
I'm trying to use DEoptim
optimization package in R on a continuous optimization problem, and as my cost function takes a long time to evaluate (2min), I'm trying to use parallel computation. My questions are:
What's the difference between paralleltype=1
(parallel
) and 2
(foreach
) option ? When to use one of the two ?
Is it possible to specify the number of cores with paralleltype=1
, in order not to take all the available cores for computing (50 cores on 64 cores available, for instance)?
Upvotes: 4
Views: 1576
Reputation: 1
Thank you for your code mjaniec!
I know it has been a while since you posted it, but I think in line 91 it should be:
cl <- parallel::makeCluster(useCores)
instead of:
cl <- parallel::makeCluster(parallel::detectCores())
Upvotes: 0
Reputation: 1114
ad. 1 - It is explained in the package documentation.
ad. 2 - Requires some tinkering with two functions: DEoptim.control and DEoptim
First, add a variable - say limitCores - to DEoptim.control function, which controls execution parameters of the DE optimization.
Second, introduce modification to the DEoptim wrapper function to act on the limitation set by limitCores.
if (ctrl$parallelType == 1) {
if (!is.na(ctrl$limitCores)) {
if (ctrl$limitCores<1) useCores <- round(parallel::detectCores()*ctrl$limitCores) else useCores <- ctrl$limitCores
cl <- parallel::makeCluster(parallel::detectCores())
} else {
cl <- parallel::makeCluster(parallel::detectCores())
}
Complete code: http://pastebin.com/NumDx4ae
Upvotes: 1