An example of mcparallel/mccollect to perform parallel tasks by creating external tasks.
library(parallel)
loop_function <- function (name, duration) {
start_time <- date()
i <- 0
while (i < duration) {
i <- i + 1
}
return (paste("Done: Job: ", name, "from", start_time, " to ", date()))
}
jobs_parallel <- lapply(1:9, function(x) mcparallel(loop_function(x, 3000000), name = x))
mccollect(jobs_parallel)
jobs_serial <- lapply(1:9, function(x) loop_function(x, 3000000))
jobs_serial
credits:
http://www.slideshare.net/bytemining/taking-r-to-the-limit-high-performance-computing-in-r-part-1-parallelization-la-r-users-group-727
http://stat.ethz.ch/R-manual/R-devel/library/parallel/doc/parallel.pdf
No comments:
Post a Comment