我正在尝试在R中使用DEoptim优化包来解决连续优化问题,并且由于我的成本函数需要很长时间来评估(2分钟),我正在尝试使用并行计算。 我的问题是:
paralleltype=1 ( parallel )和2 ( foreach )选项有什么区别? 什么时候使用其中一个?
是否可以指定paralleltype=1的核心数,以便不占用所有可用的核心进行计算(例如,64个核心上有50个核心可用)?
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)?
最满意答案
广告。 1 - 包文档中对此进行了解释。
广告。 2 - 需要对两个函数进行修改:DEoptim.control和DEoptim
首先,将一个变量 - 例如limitCores - 添加到DEoptim.control函数,该函数控制DE优化的执行参数。
其次,对DEOPtim包装函数进行修改,以对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()) }完整代码: http : //pastebin.com/NumDx4ae
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
更多推荐
发布评论