# Only run if a Redis server is running
if (redux::redis_available()) {
## The example assumes that a Redis server is running on the local host
## and standard port.
# 1. Start a single local R worker process
startLocalWorkers(n=1, queue="jobs", linger=1)
# 2. Run a simple sampling approximation of pi:
registerDoRedis("jobs")
pie = foreach(j=1:10, .combine=sum, .multicombine=TRUE) %dopar%
4 * sum((runif(1000000) ^ 2 + runif(1000000) ^ 2) < 1) / 10000000
removeQueue("jobs")
print(pie)
# Note that removing the work queue automatically terminates worker processes.
}
Run the code above in your browser using DataLab