How can I make R using more than 1 core (8 available) on a Ubuntu Rstudio server?

1.5k Views Asked by At

I want to run the glmer procedure in lme4 package on a large dataset (250,000 observations). The model takes more than 15 min to run on a laptop. We are using a Rstudio server based on Ubuntu. The problem is that 8 cores are available on this server but when I run the glmer procedure, only 1 of them is being used and it takes more than 1h to get the results... How can I solve that problem and improve time efficiency? I found on google I may have to use the parallel procedure but I am not familiar at all with those informatics procedures and they look very complex to me... Can anyone help with a simple procedure to tackle the problem?

I know they have been questions on the topic already but that was 7 years ago (R package that automatically uses several cores?) or 3 years ago (How can I make R use more CPU and memory?). I know R packages and procedures are evolving and I wanted your help on an update on this topic (and hopefully a straightforward, easy solution).

1

There are 1 best solutions below

1
On

something like the following would help?

library(parallel)
f <- function(i) {
  lmer(Petal.Width ~ . - Species + (1 | Species), data = iris)
}
cls <- makeCluster(detectCores())
clusterEvalQ(cls, library(lme4))
mod <- parLapply(cls, 1, f)
stopCluster(cls)