Just add something to Steve: I think that the decisive point is that the parallel backend starts several Rscript.exe processes (as seen from the task manager). Some objects that are used in foreach , i.e. In your case, x is then copied to the memory that was allocated for each of these processes. I'm not sure how copying is handled in the foreach package, but with the *ply functions of the *ply package plyr you need to explicitly specify the objects you want to copy. Different processes do not share their memory. (I don't know of other R packets that can use shared memory ...)
You can demonstrate that the matrix x is actually copied using .Internal(inspect(x)) to print the location of cell x .
library(foreach) library(doParallel) x <- matrix(1:16, nrow = 8, ncol = 2)
Matrix y reads
[,1] result.1 "@0x0000000003dab910 13 INTSXP g0c5 [NAM(1),ATT] (len=16, tl=0) 1,2,3,4,5,..." result.2 "@0x0000000003dab9b0 13 INTSXP g0c5 [NAM(1),ATT] (len=16, tl=0) 1,2,3,4,5,..." result.3 "@0x0000000003dab910 13 INTSXP g0c5 [NAM(2),ATT] (len=16, tl=0) 1,2,3,4,5,..." result.4 "@0x0000000003dab910 13 INTSXP g0c5 [NAM(2),ATT] (len=16, tl=0) 1,2,3,4,5,..." ...
Here you should find two different memory addresses.
cryo111
source share