我试图制作并行循环,但我发现R不能使用我的所有8个内核,它只使用1代码:
library(parallel)
library(foreach)
library(doParallel)
no_cores <- detectCores() - 1
cl <- makeCluster(no_cores)
registerDoParallel(cl, cores = no_cores)
sum.of.squares <- foreach(i = 1:10e4, .combine = "+", .init = 0) %dopar% {
sqrt(i)
}
stopCluster(cl)
它仅占CPU的13-15%。为什么呢?
将Windows 8.1与R 3.2.1一起使用。
答案 0 :(得分:1)
使用R Revolution Open(RRO)3.2
http://mran.revolutionanalytics.com/documents/rro/installation/
它与Intel MKL并行数学库集成。