cypress/FileTransfer/Example: bootstrap.R

File bootstrap.R, 720 bytes (added by cmaggio, 9 years ago)
Line 
1library(doParallel)
2# Enable command line arguments
3args<-commandArgs(TRUE)
4
5# use the environment variable SLURM_NTASKS_PER_NODE to set the number of cores
6registerDoParallel(cores=(as.integer(args[1])))
7
8# Bootstrapping iteration example
9x <- iris[which(iris[,5] != "setosa"), c(1,5)]
10iterations <- 10000# Number of iterations to run
11
12# Parallel version of code
13# Note the '%dopar%' instruction
14part <- system.time({
15 r <- foreach(icount(iterations), .combine=cbind) %dopar% {
16 ind <- sample(100, 100, replace=TRUE)
17 result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
18 coefficients(result1)
19 }
20})[3]
21
22# Shows the number of Parallel Workers to be used
23getDoParWorkers()
24# Executes the functions
25part