rparallel-processingdomc

multicore on Linux does not use multiple CPUs


I am using R 2.14.0 64 bit on Linux. I went ahead and used the example described here. I am then running the example -

library(doMC)
registerDoMC()
system.time({
r <- foreach(icount(trials), .combine=cbind) %dopar% {
  ind <- sample(100, 100, replace=TRUE)
  result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
  coefficients(result1)
} })

However, I see in top that it is using only one CPU core. To prove it another way, if I check a process that uses all cores, I see -

ignorant@mybox: ~/R$ ps -p 5369 -L -o pid,tid,psr,pcpu
  PID   TID PSR %CPU
 5369  5369   0  0.1
 5369  5371   1  0.0
 5369  5372   2  0.0
 5369  5373   3  0.0
 5369  5374   4  0.0
 5369  5375   5  0.0
 5369  5376   6  0.0
 5369  5377   7  0.0

But in this case, I see -

ignorant@mybox: ~/R$ ps -p 7988 -L -o pid,tid,psr,pcpu
  PID   TID PSR %CPU
 7988  7988   0 19.9
ignorant@mybox: ~/R$ ps -p 7991 -L -o pid,tid,psr,pcpu
  PID   TID PSR %CPU
 7991  7991   0 19.9

How can I get it to use multiple cores? I am using multicore instead of doSMP or something else, because I do not want to have copies of my data for each process.


Solution

  • You could try executing your script using the command:

    $ taskset 0xffff R --slave -f parglm.R
    

    If this fixes the problem, then you may have a version of R that was built with OpenBLAS or GotoBlas2 which sets the CPU affinity so that you can only use one core, which is a known problem.

    If you want to run your example interactively, start R with:

    $ taskset 0xffff R