This document discusses using parallel computing in R with the snow package. It provides an overview of using snow to distribute computations across multiple CPUs. Examples are given showing how snow can be used with functions like parApply to speed up matrix multiplication by performing the operation in parallel on a cluster. The document also discusses using snow together with Rmpi and a job scheduler like Sun Grid Engine to enable parallel computing on a computing cluster.
19. matprod.R
? 1000
n <- 1000
A <- matrix(rnorm(n^2), n)
B <- matrix(rnorm(n^2), n)
C <- A %*% B
?
20. clmatprod.R
library(snow)
n <- 1000
A <- matrix(rnorm(n^2), n)
B <- matrix(rnorm(n^2), n)
cpu <- 2
hosts <- rep("localhost", cpu)
cl <- makeCluster(hosts, type="SOCK")
C <- parMM(cl, A, B) # C <- A %*% B
stopCluster(cl)