Parallel Programming in R
Nabeel Imam
Data Scientist
Building a floor on top of the last one: sequential
Installing windows to finished structure: parallel
Calculating the square roots of a million numbers
numbers <- 1:1000000
start <- Sys.time() sq_roots <- lapply(numbers, sqrt) end <- Sys.time()
end - start
Time difference of 1.044573 secs
The square roots of a million numbers in parallel
library(parallel)
my_cluster <- makeCluster(3)
start <- Sys.time() sq_roots <- parLapply(my_cluster, numbers, sqrt) end <- Sys.time()
stopCluster(my_cluster)
end - start
Time difference of 0.8416824 secs
For a sufficiently complex task, consider:
Pros
Cons
Parallel Programming in R