It's probably working (at least it does on my mac). However, one call to runif
takes such a small amount of time that all the time is spent for the overhead and the child processes spend negligible CPU power with the actual tasks.
x <- foreach(i=1:20) %dopar% {
system.time(runif(pois[i]))
}
x[[1]]
#user system elapsed
# 0 0 0
Parallelization makes sense if you have some heavy computations that cannot be optimized. That's not the case in your example. You don't need 1e6 calls to runif
, one would be sufficient (e.g., runif(sum(pois))
and then split the result).
PS: Always test with a smaller example.