Patrick McCarthy Patrick McCarthy - 8 months ago 55
R Question

How to kill a doMC worker when it's done?

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.



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

##kill command here?

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

Answer Source

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

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

## computation


Works every time.