我很难弄清楚为什么这段代码不能并行化。我将直接从插入符号网页上获取可重复的示例。
library(caret)
library(mlbench)
library(Hmisc)
library(randomForest)
library(doMC)
registerDoMC(cores = 3)
n <- 100
p <- 40
sigma <- 1
set.seed(1)
sim <- mlbench.friedman1(n, sd = sigma)
colnames(sim$x) <- c(paste("real", 1:5, sep = ""),
paste("bogus", 1:5, sep = ""))
bogus <- matrix(rnorm(n * p), nrow = n)
colnames(bogus) <- paste("bogus", 5+(1:ncol(bogus)), sep = "")
x <- cbind(sim$x, bogus)
y <- sim$y
normalization <- preProcess(x)
x <- predict(normalization, x)
x <- as.data.frame(x)
subsets <- c(1:5, 10, 15, 20, 25)
set.seed(10)
ctrl <- rfeControl(functions = lmFuncs,
method = "repeatedcv",
repeats = 50,
verbose = FALSE)
lmProfile <- rfe(x, y,
sizes = subsets,
rfeControl = ctrl)
plot(lmProfile)
所有运行流畅但使用并行化代码行:
library(doMC)
registerDoMC(cores = 3)
前一个示例使用的是1个核心。如果没有并行化代码,前面的示例使用2个内核。我正在使用&#39; top&#39;和&#39; htop&#39;检查核心数量。我想要使用我的所有4个核心而且我不知道问题在哪里。
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] BradleyTerry2_1.0-5 brglm_0.5-9 car_2.0-20 caret_6.0-30 codetools_0.2-8 colorspace_1.2-4 digest_0.6.4 foreach_1.4.2 ggplot2_1.0.0
[10] grid_3.1.0 gtable_0.1.2 gtools_3.4.1 iterators_1.0.7 kernlab_0.9-19 lattice_0.20-29 lme4_1.1-7 MASS_7.3-31 Matrix_1.1-3
[19] minqa_1.2.3 munsell_0.4.2 nlme_3.1-117 nloptr_1.0.0 nnet_7.3-8 plyr_1.8.1 proto_0.3-10 Rcpp_0.11.1 reshape2_1.4
[28] scales_0.2.4 splines_3.1.0 stringr_0.6.2
更新:使用R版本3.0.3一切正常。似乎是一个错误。解决方案 - &gt;降级R