Rev 67806 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
## not necessarily reproducible examples.library(parallel)cl <- makeCluster(getOption("cl.cores", 2))clusterApply(cl, 1:2, get("+"), 3)xx <- 1clusterExport(cl, "xx")clusterCall(cl, function(y) xx + y, 2)## Use clusterMap like an mapply exampleclusterMap(cl, function(x,y) seq_len(x) + y,c(a = 1, b = 2, c = 3), c(A = 10, B = 0, C = -10))parSapply(cl, 1:20, get("+"), 3)## PR14898parSapply(cl, 1, identity)if(require(boot)) {## A bootstrapping example, which can be done in many ways:clusterEvalQ(cl, {## set up each worker. Could also use clusterExport()library(boot)cd4.rg <- function(data, mle) MASS::mvrnorm(nrow(data), mle$m, mle$v)cd4.mle <- list(m = colMeans(cd4), v = var(cd4))NULL})res <- clusterEvalQ(cl, boot(cd4, corr, R = 100,sim = "parametric", ran.gen = cd4.rg, mle = cd4.mle))cd4.boot <- do.call(c, res)print(boot.ci(cd4.boot, type = c("norm", "basic", "perc"),conf = 0.9, h = atanh, hinv = tanh))}stopCluster(cl)