The original readme had the following code example.
library(doParallel)
registerDoParallel(3)
mod_list2 <- foreach(dat=dat_list) %dopar% {
lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=dat)
}
stopImplicitCluster()
In Windows, writing code this way will cause a residual "R for Windows front-end" process to appear in Task Manager after the code finishes running, thus consuming RAM. The following method can avoid this situation.
library(doParallel)
cl <- makeCluster(3)
registerDoParallel(cl)
mod_list2 <- foreach(dat=dat_list) %dopar% {
lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=dat)
}
stopCluster(cl)
rm(cl)
gc()
The original readme had the following code example.
In Windows, writing code this way will cause a residual "R for Windows front-end" process to appear in Task Manager after the code finishes running, thus consuming RAM. The following method can avoid this situation.