runParallel {pnd} | R Documentation |
Run a function in parallel over a list (internal use only)
Description
Run a function in parallel over a list (internal use only)
Usage
runParallel(FUN, x, cores = 1L, cl = NULL, preschedule = FALSE)
Arguments
FUN |
A function of only one argument. If there are more arguments, use
the |
x |
A list to parallelise the evaluation of |
cores |
Integer specifying the number of CPU cores used for parallel computation. Recommended to be set to the number of physical cores on the machine minus one. |
cl |
An optional user-supplied |
preschedule |
Logical: if |
Value
The value that lapply(x, FUN)
would have returned.
Examples
fslow <- function(x) Sys.sleep(x)
x <- rep(0.05, 6)
cl <- parallel::makeCluster(2)
print(t1 <- system.time(runParallel(fslow, x)))
print(t2 <- system.time(runParallel(fslow, x, cl = cl)))
print(t3 <- system.time(runParallel(fslow, x, cores = 2)))
parallel::stopCluster(cl)
cat("Parallel overhead at 2 cores: ", round(t2[3]*200/t1[3]-100), "%\n", sep = "")
# Ignore on Windows
cat("makeCluster() overhead at 2 cores: ", round(100*t2[3]/t3[3]-100), "%\n", sep = "")