Debian Codegraph @

inst/testme/test-isForkedChild.R

raw
1 library(parallelly)
2 library(parallel)
3
4 message("*** isForkedChild() ...")
5
6 stopifnot(!isForkedChild())
7
8 if (supportsMulticore()) {
9 message("- mcparallel()/mccollect()")
10 f <- mcparallel(isForkedChild())
11 isForked <- mccollect(f)[[1]]
12 stopifnot(isForked)
13
14 message("- makeForkCluster()")
15 cl <- makeForkCluster(1L)
16 isForked <- clusterEvalQ(cl, { parallelly::isForkedChild() })
17 isForked <- unlist(isForked, use.names = FALSE)
18 stopifnot(isForked)
19 parallel::stopCluster(cl)
20 }
21
22 message("- mclapply()")
23 isForked <- mclapply(1:2, FUN = function(ii) isForkedChild())
24 isForked <- unlist(isForked, use.names = FALSE)
25 if (supportsMulticore()) {
26 stopifnot(all(isForked))
27 } else {
28 stopifnot(!any(isForked))
29 }
30
31 message("- makeClusterPSOCK()")
32 cl <- makeClusterPSOCK(1L)
33 isForked <- clusterEvalQ(cl, { parallelly::isForkedChild() })
34 isForked <- unlist(isForked, use.names = FALSE)
35 stopifnot(!isForked)
36 parallel::stopCluster(cl)
37
38 message("*** isForkedChild() ... DONE")