Using the foreach package, I was expecting the following line to run in about 10 seconds
system.time(foreach (i=1:5, .combine='c') %do% {Sys.sleep(2);i})
user system elapsed
0.053 0.011 10.012
and the following line to run in about 2 seconds
system.time(foreach (i=1:5, .combine='c') %dopar% {Sys.sleep(2);i})
user system elapsed
0.069 0.017 10.019
but it doesn't work.
I am on a Mac OSX, my machine has 16 processors and nothing heavy is currently running. I don't get any error or warning message.
You need to register a parallel backend. Do something like
library(doParallel)
registerDoParallel(cores=4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With