Skip to content

Simple example for High performance computing with R?

3 messages · Fabrice Tourre, Martin Morgan, Brian Ripley

#
Dear list,

I want to run two independent calculation (A, B) and then combined
their results to do a plot in R. Before I just run calculation A
first, then calculation B. It will take some times. I just have one
server with multiple core. I noticed that there are some nice package
in R for parallel calculation, such as parallel, multicore and snow.
Also there is a book, O?Reilly ? ?Parallel R, Data Analysis in the
Distributed World? book by Q. Ethan McCallum and Stephen Weston.

When track into these packages, I am a little of lost because I did
not know parallel calculation too much.

Could any one can give me some example codes for my purpose? So I can
easy follow.

Thank you very much in advance.
#
On 05/29/2012 08:02 PM, Fabrice Tourre wrote:
Here we sleep for 20 seconds, but do it in only 5 seconds!

 > library(parallel)
 > system.time(mclapply(1:4, function(i) Sys.sleep(5), mc.cores=4))
    user  system elapsed
   0.006   0.025   5.021

Often, it is possible to use mclapply just like lapply; use the 
'parallel' library, and for single processor machines the mclapply and 
similar functions rather than parLapply and similar. This

   vignette("parallel", package="parallel")

might provide further help. Likely you will get benefit from making your 
calculation A use parallel calculations, and B use parallel calculation.

Martin

  
    
#
On 30/05/2012 04:02, Fabrice Tourre wrote:
Please read the vignette for package 'parallel': we already answered 
your request.