Memory optimization in parallel computing for R

Viewed 224

I'm facing a problem with parallel computing in R regarding memory allocation.

I'm experiencing that the memory usage starts to grow and grow so that, in some point, it runs out.

For examples, please have a look to this code:

library(parallel)
set.seed(100)
data <- runif(100000000)
val <- mclapply(1:length(data), function(x) {data[x]/2}, mc.cores=3)

If I use more than one core, I miss the control over the memory management (in a machine with 8GB of RAM, I get into swap very quickly). Taking into account that data is a shared variable that shouldn't be replicated at each instance, which the best way of accessing to such resource only for reading purposes?

0 Answers
Related