[R] Issue with mcapply

AROONALOK PYNE aroonalok.pyne at gmail.com
Thu Jun 11 10:32:56 CEST 2015


Please check this code :

library(parallel)
workerFunc <- function(n) { return(n^2) }
a <- function(){
  CurrentTime <- Sys.time()
  res <- lapply(values, workerFunc)
  TimeTaken <- Sys.time() - CurrentTime
  print(TimeTaken)
}
b <- function(){
  CurrentTime <- Sys.time()
  numWorkers <- detectCores()
  res <- mclapply(values, workerFunc, mc.cores = numWorkers-2)
  TimeTaken <- Sys.time() - CurrentTime
  print(TimeTaken)
}
c <- function(n){
  values <<- 1:n
  print("Evaluating a : ")
  a()
  print("Evaluating b : ")
  b()
}

For large values of n, the code calculates a() but the hangs indefinitely
on reaching b(). How do I correct it ?
I am using Ubuntu 14.04 and core i7 Processor

-- 
*AROONALOK PYNE*

BE Graduate
Department Of Computer Science And Engineering
Jadavpur University, Kolkata-32
India

	[[alternative HTML version deleted]]



More information about the R-help mailing list