2 min read

Saturation with Parallel Computation in R


I have just saturated all my PC:

full is the 4gb RAM


and so is the CPU (I7 4770 @3.4 GHZ)


Parallel Computation in R

which is my secret?

the doParallel package for R on mac

The package lets you make some very useful parallel computation, giving you the possibility to use all the potentiality of your CPU.

As a matter of fact, the standard R option is to use  just on of the cores you have got on your PC.

With parallel computation, just to say it easy, you can take your job, divide it in some smaller jobs, solve them and then put them together  in one new R object.

Tutorial ( More or Less)

There are some useful tutorial on the web (try to google it), but let me introduce the stuff in a really basic way so that you can immediately try it out:

install.packages("doParallel") library(doParallel) cl = makeCluster(2) # if you want to use all your fire power, put the number of your cores registerDoParallel(cl) parallelization = function(x){ n = number #put here the number of repetitions you need foreach ( i=1:n,.combine = rbind) { #this '.combine = rbind' let R understand that has to put the results together with an rbind function, you can use cbind as well x*2 } }

Final Warnings


sorry about the capital letters but I have been stacked on this error for quite a long time…

Finally, are you using Windows? instead of doParallel you can obtain the same result with doSNOW package.

comments are welcome.

comments disclaimer
thank you for taking the time to comment. If the comment you are about to write is related to a piece of code I wrote, please reach its Github respository and place there any request of improvement or report of bugs.