速度, 本來需要578.18 secs, 加上平行化後只需209.99 secs.
R 程式碼
rm(list=ls()) library(snow) myfun <- function(ii) { set.seed(ii*100) ret = mean(rnorm(10000)) ret } cluster = makeCluster(4,type="MPI") ### Normal tt0 = Sys.time() aa = sapply(1:100000,myfun) tt1 = Sys.time() bb = parSapply(cluster,1:100000,myfun) tt2 = Sys.time() stopCluster(cluster) cat(sprintf(" - %.4f, %.4f\n",difftime(tt1,tt0,units="secs"),difftime(tt2,tt1,units="secs")))