File: isForkedChild.R

package info (click to toggle)
r-cran-parallelly 1.42.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,216 kB
  • sloc: ansic: 111; sh: 13; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
source("incl/start.R")
library(parallel)
options(parallelly.debug = FALSE)

message("*** isForkedChild() ...")

stopifnot(!isForkedChild())

if (supportsMulticore()) {
  message("- mcparallel()/mccollect()")
  f <- mcparallel(isForkedChild())
  isForked <- mccollect(f)[[1]]
  stopifnot(isForked)

  message("- makeForkCluster()")
  cl <- makeForkCluster(1L)
  isForked <- clusterEvalQ(cl, { parallelly::isForkedChild() })
  isForked <- unlist(isForked, use.names = FALSE)
  stopifnot(isForked)
  parallel::stopCluster(cl)
}

message("- mclapply()")
isForked <- mclapply(1:2, FUN = function(ii) isForkedChild())
isForked <- unlist(isForked, use.names = FALSE)
if (supportsMulticore()) {
  stopifnot(all(isForked))
} else {
  stopifnot(!any(isForked))
}

message("- makeClusterPSOCK()")
cl <- makeClusterPSOCK(1L)
isForked <- clusterEvalQ(cl, { parallelly::isForkedChild() })
isForked <- unlist(isForked, use.names = FALSE)
stopifnot(!isForked)
parallel::stopCluster(cl)

message("*** isForkedChild() ... DONE")

source("incl/end.R")