# A lazy sqrt function which doesn't care about efficiency
lazySqrt <- function(num) {
# Sleep randomly between 0 to 1 second
Sys.sleep(runif(1))
return(sqrt(num))
}
# Get the sqrt of 1-5 in parallel
if (length(grep("windows", Sys.info()["sysname"], ignore.case = TRUE))) {
# Windows Machine does not support mc(*)apply
result <- pbmclapply(1:5, lazySqrt, mc.cores = 1)
} else {
# Get the sqrt of 1-5 in parallel
result <- pbmclapply(1:5, lazySqrt)
}
Run the code above in your browser using DataLab