Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'mclapply' for Windows

Tags:

r

I am working with the BTYD plus code given in https://github.com/mplatzer/BTYDplus/blob/master/R/pareto-nbd-mcmc.r . This code uses the MCMC technique to estimate the Pareto/NBD parameters of the BTYD Model.

So, If you see line 224-228 of the code, it uses the function 'mclapply'- which I found can run only on Linux or MAC. I am working on a windows machine and need to convert this part of the code such that I am able to execute it on a Windows machine as well. So, Can anyone help me with this specific code or could give a general idea of how to use 'mclapply' for windows ?

like image 431
Saurabh Avatar asked Dec 25 '22 12:12

Saurabh


1 Answers

Use parLapply:

Sys.info()["sysname"]
#  sysname 
#"Windows"

library(parallel)
cl <- makeCluster(getOption("cl.cores", 2))
l <- list(1, 2)
system.time(
parLapply(cl, l, function(x) {
  Sys.sleep(10)
  })
)
#user  system elapsed 
#0       0      10 

stopCluster(cl)

You might want to look into the doRNG package for reproducibility if your tasks include random number generation.

like image 196
Roland Avatar answered Jan 13 '23 05:01

Roland