Skip to content

Instantly share code, notes, and snippets.

@ajdamico
Created December 10, 2010 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajdamico/736887 to your computer and use it in GitHub Desktop.
Save ajdamico/736887 to your computer and use it in GitHub Desktop.
run multicore processing in the windows 64 bit version of R
library(snowfall)
bigProcess <- function( x ) {
mean( replicate ( 10^6 , max( rnorm( 100 , x ) ) ) )
}
#run the function twice in parallel
start <- Sys.time()
sfInit(cpus=2,type='SOCK',parallel=TRUE)
sfSapply( c(1,5) , bigProcess )
Sys.time() - start
#faster than running it twice sequentially
start <- Sys.time()
bigProcess( 1 )
bigProcess( 5 )
Sys.time() - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment