使用doFuture包完成并行计算后,如何关闭额外的R会话?

huangapple go评论59阅读模式
英文:

How to close additional R sessions when parallel computing is completed using doFuture package?

问题

我正在尝试使用doFuture包进行并行计算。以下是该包文档中的代码。

library(doFuture)
plan(multisession)

cutoff <- 0.10
y <- foreach(x = mtcars) %dofuture% {
  mean(x, trim = cutoff)
}
names(y) <- colnames(mtcars)

当计算完成时,用于并行计算的额外R会话没有关闭。当我使用doParallel包时,我使用以下代码创建集群:

cl <- makeCluster(cores)
registerDoParallel(cl)

并使用以下代码停止集群:

closeCluster(cl)

在使用doFuture包时,如何关闭这些R会话呢?

英文:

I'm trying to use doFuture package for parallel computing. Here is the code from the document of the package.

library(doFuture)
plan(multisession)

cutoff &lt;- 0.10
y &lt;- foreach(x = mtcars) %dofuture% {
  mean(x, trim = cutoff)
}
names(y) &lt;- colnames(mtcars)

When the computing is completed, the additional R sessions for parallel computing are not closed. When I use doParallel package, I use the following to make cluster

cl &lt;- makeCluster(cores)
registerDoParallel(cl)

and use the following code to stop cluster.

closeCluster(cl)

How do I close these R sessions when using the doFuture package?

答案1

得分: 2

将计划设置为sequential()将关闭额外的R会话。

英文:

Setting the plan to sequential() will close the extra R sessions.

plan(sequential)

huangapple
  • 本文由 发表于 2023年7月28日 01:39:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782242.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定