Pergunta

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.

Foi útil?

Solução

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

Outras dicas

First, you might want to look at htop, which is probably available for your distribution. You can clearly see the usage for each CPU.

Second, have you tried setting the number of cores on the machine directly?

Run this with htop open:

library(doMC)
registerDoMC(cores=12) # Try setting this appropriately.
system.time({
  r <- foreach(1:1000, .combine=cbind) %dopar% {
    mean(rnorm(100000))
  } })
# I get:
#    user  system elapsed 
#  12.789   1.136   1.860 

If the user time is much higher than elapsed (not always -- I know, but a rule of thumb), you are probably using more than one core.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top