File: utils.R

package info (click to toggle)
r-cran-parallelmap 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 336 kB
  • sloc: sh: 13; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,452 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
# show message if OPTION show.info is TRUE
#  show.info ARGUMENT provides an immediate OVERRIDE to that option
showInfoMessage = function(msg, ..., show.info = NA) {
  if (ifelse(is.na(show.info), getPMOptShowInfo(), show.info)) {
    messagef(msg, ...)
  }
}

showStartupMsg = function(mode, cpus, socket.hosts) {
  if (mode != MODE_LOCAL) {
    if (mode %in% c(MODE_MULTICORE, MODE_MPI) ||
      (mode == MODE_SOCKET && !is.na(cpus))) {
      showInfoMessage("Starting parallelization in mode=%s with cpus=%i.",
        mode, cpus)
    } else if (mode == MODE_SOCKET) {
      showInfoMessage("Starting parallelization in mode=%s on %i hosts.",
        mode, length(socket.hosts))
    } else if (mode == MODE_BATCHJOBS) {
      showInfoMessage("Starting parallelization in mode=%s-%s.",
        mode, BatchJobs::getConfig()$cluster.functions$name)
    }
  }
}

# either the option level is not set or it is and the level of parmap matches
isParallelizationLevel = function(level) {
  optlevel = getPMOptLevel()
  is.na(optlevel) || (!is.na(level) && level == optlevel)
}

exportToSlavePkgParallel = function(objname, objval) {
  # clusterExport is trash because of envir argument, we cannot easily export
  # stuff defined in the scope of an R function
  # cl = NULL is default cluster, pos=1 is always globalenv
  # I really hope the nextline does what I think in all cases...
  clusterCall(cl = NULL, assign, x = objname, value = objval, pos = 1)
}