Skip to content

Commit

Permalink
Maximum number of local workers are skipped if 'nworkers' inherits fr…
Browse files Browse the repository at this point in the history
…om 'AsIs' [#107]
  • Loading branch information
HenrikBengtsson committed Feb 2, 2024
1 parent c26d78c commit 9c6e469
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: parallelly
Version: 1.36.0-9015
Version: 1.36.0-9016
Title: Enhancing the 'parallel' Package
Imports:
parallel,
Expand Down
9 changes: 5 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

* `makeClusterPSOCK(nworkers)` gained protection against setting up
too many localhost workers relative to number of available CPU
cores. If `nworkers / availableCores()` greater than 1.0 (100%),
then a warning is produced. If greater than 2.0 (200%), an error
is produced. These limits can be configured by R option
`parallelly.maxWorkers.localhost`.
cores. If `nworkers / availableCores()` greater than 1.0 (100%),
then a warning is produced. If greater than 2.0 (200%), an error is
produced. These limits can be configured by R option
`parallelly.maxWorkers.localhost`. These checks are skipped if
`nworkers` inherits from `AsIs`, e.g. `makeClusterPSOCK(I(16))`.


## Miscellaneous
Expand Down
2 changes: 2 additions & 0 deletions R/availableCores.R
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ getNproc <- function(ignore = c("OMP_NUM_THREADS", "OMP_THREAD_LIMIT")) {


checkNumberOfLocalWorkers <- function(workers) {
if (inherits(workers, "AsIs")) return()

rhos <- getOption("parallelly.maxWorkers.localhost", c(1.0, 2.0))
if (length(rhos) == 0) return()

Expand Down
3 changes: 2 additions & 1 deletion R/makeClusterPSOCK.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ makeClusterPSOCK <- function(workers, makeNode = makeNodePSOCK, port = c("auto",
if (length(workers) != 1L) {
stopf("When numeric, argument 'workers' must be a single value: %s", length(workers))
}
workers <- as.integer(workers)

workers <- structure(as.integer(workers), class = class(workers))
if (is.na(workers) || workers < 1L) {
stopf("Number of 'workers' must be one or greater: %s", workers)
}
Expand Down

0 comments on commit 9c6e469

Please sign in to comment.