I've been experimenting with parallel computing in R using the doParallel
package. From what I understand, depending on how you call registerDoParallel
, you might use the multicore
API or the snow
API.
For example, to make use of forking with multicore
, you'd do something like this:
registerDoParallel(4)
And to make use of forking with snow
, you'd do something like this:
cl <- makeCluster(4, type="FORK")
registerDoParallel(cl)
I have a fairly simple job* that is calculating summary statistics on a matrix object. However, even though both of these approaches ostensibly make use of forking (and thus all child jobs should have access to the same address space for working with this matrix), I'm getting wildly different performance/memory usage. (In particular, multicore
works substantially better.)
Before I try to diagnose this further, I thought I'd ask: Does anyone have an intuitive explanation for why this would be happening, and if this is normal? I've been searching everywhere for a resource that breaks down the differences between the two, but I've been unable to find anything that breaks it down in detail. Are there cases where, say, the multicore
version would run and the snow
version wouldn't (due to memory issues)?
(Note: This is all on a Mac with 16 GB of RAM. I did read these threads -- Does multicore computing using R's doParallel package use more memory? and reading global variables using foreach in R -- which almost address my concern but not quite.)
*I'm happy to provide my code, but it didn't seem relevant for this example. I'm hoping for a more general breakdown of the differences between these two approaches.