R: parallelをつかってみる [統計]
R 2.14.0から標準装備となったparallelパッケージをためしてみた。
library(boot) n <- 10000 m <- 5000 c <- 3 x <- vector("list", c) for (i in 1:c) { x[[i]] <- runif(n, 0, 1) } boot.fun <- function(data, index) { mean(data[index]) } system.time(z1 <- lapply(1:c, function(i) boot(x[[i]], boot.fun, m))) ## parallel library(parallel) RNGkind("L'Ecuyer-CMRG") system.time(z2 <- mclapply(1:c, function(i) boot(x[[i]], boot.fun, m)))
結果
> system.time(z1 <- lapply(1:c, + function(i) + boot(x[[i]], boot.fun, m))) ユーザ システム 経過 7.012 1.606 8.558 > system.time(z2 <- mclapply(1:c, + function(i) + boot(x[[i]], boot.fun, m))) ユーザ システム 経過 3.118 0.552 7.203
タグ:R
コメント 0