Home > other >  Is there any simple task that allows me to understand whether my embarassingly parallel program work
Is there any simple task that allows me to understand whether my embarassingly parallel program work

Time:02-04

I am employing an embarassingly parallel routine using mclapply() of the parallel package in R in order to simulate independent paths of a stochastic process. I am surprised that I could not get any speed gain over the non-parallel program, though.

Is there any task which is established to be performed faster in parallel than on a single core which I can use to check whether the system is working as expected?

CodePudding user response:

you could try executing

Sys.sleep(5)

which suspends the session for 5 seconds. If the parallelisation works, then each of the worker processes should be sleeping at the same time.


library(parallel)
library(tictoc)

f <- function(...) {
  Sys.sleep(1) 
  "DONE"
}

tic()
res <- lapply(1:5, f)
toc()
#> 5.025 sec elapsed

tic()
res <- mclapply(1:5, f, mc.cores = 5)
toc()
#> 1.019 sec elapsed

Created on 2023-02-03 with reprex v2.0.2

  • Related