Reputation: 24168
I was trying to make a parallel loop, but I've found R can't utilize all my 8 cores, it uses only 1 with this code:
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)
It uses only about 13-15% of CPU. Why?
Using Windows 8.1 with R 3.2.1.
Upvotes: 1
Views: 2288
Reputation: 3634
Use R Revolution Open (RRO) 3.2
http://mran.revolutionanalytics.com/documents/rro/installation/
It comes integrated with the Intel MKL parallel math libraries.
See a fuller comparison here.
Upvotes: 1