本文介绍了完成后如何杀死 doMC 工人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

doMC 的文档似乎很少,只列出了 doMC-package 和 registerDoMC().我遇到的问题是我将通过 doMC/foreach 产生几个工人,但是当工作完成后,他们只是坐在那里占用内存.我可以去寻找他们的进程 ID,但我经常不小心杀死主进程.

The documentation for doMC seems very sparse, listing only doMC-package and registerDoMC(). The problem I'm encountering is I'll spawn several workers via doMC/foreach, but then when the job is done they just sit there taking up memory. I can go and hunt their process IDs, but I often kill the master process by accident.

library(doMC)
library(foreach)

registerDoMC(32)

foreach(i=1:32) %dopar% foo()

##kill command here?

我尝试使用 registerDoSEQ() 进行跟踪,但它似乎并没有终止进程.

I've tried following with registerDoSEQ() but it doesn't seem to kill off the processes.

推荐答案

我从来没有为 doMC 找到合适的解决方案,所以有一段时间我一直在做以下事情:

I never did find a suitable solution for doMC, so for a while I've been doing the following:

library(doParallel)
cl <- makePSOCKcluster(4) # number of cores to use
registerDoParallel(cl)

## computation

stopCluster(cl)

每次都有效.

这篇关于完成后如何杀死 doMC 工人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:34