Skip to content

Commit

Permalink
BUG FIX: availableCores() was numeric rather than integer
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Jan 22, 2025
1 parent 3be753a commit 5ddcd0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 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.41.0-9009
Version: 1.41.0-9010
Title: Enhancing the 'parallel' Package
Imports:
parallel,
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
both CGroups v1 and CGroups v2 are enabled on the
machine. Previously, such configurations were completely ignored.


## Bug Fixes

* Call `isNodeAlive()` and `killNode()` on cluster nodes running on
external machines would produce `Error in match.arg(type, choices =
known_types, several.ok = FALSE) : 'arg' must be of length 1`. This
bug was introduced in version 1.38.0 (2024-07-27), when adding
richer support for the `rscript_sh` argument.

* The value of `availableCores()` was numeric rather than integer as
documented. This harmless bug was introduced in version 1.31.0
(2022-04-07).


# Version 1.41.0 [2024-12-17]
Expand Down
10 changes: 7 additions & 3 deletions R/availableCores.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,18 @@ availableCores <- function(constraints = NULL, methods = getOption2("parallelly.
} else if (method == "cgroups.cpuquota") {
## Number of cores according to Unix cgroups v1 CPU quota
n <- getCGroups1CpuQuota()
if (!is.na(n)) {
if (is.na(n)) {
n <- NA_integer_
} else {
n <- as.integer(floor(n + 0.5))
if (n == 0L) n <- 1L ## If CPU quota < 0.5, round up to one CPU
}
} else if (method == "cgroups2.cpu.max") {
## Number of cores according to Unix cgroups v2 CPU max quota
n <- getCGroups2CpuMax()
if (!is.na(n)) {
if (is.na(n)) {
n <- NA_integer_
} else {
n <- as.integer(floor(n + 0.5))
if (n == 0L) n <- 1L ## If CPU max quota < 0.5, round up to one CPU
}
Expand All @@ -333,10 +337,10 @@ availableCores <- function(constraints = NULL, methods = getOption2("parallelly.
on.exit(options(oopts))
fcn()
})
n <- as.integer(n)
if (length(n) != 1L) {
stop("Function specified by option 'parallelly.availableCores.custom' does not a single value")
}
n <- as.integer(n)
} else {
## covr: skip=3
## Fall back to querying option and system environment variable
Expand Down
7 changes: 4 additions & 3 deletions tests/availableCores.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stopifnot(length(n) == 1, is.numeric(n))
## Default
n <- availableCores()
message(sprintf("availableCores() = %d", n))
stopifnot(length(n) == 1, is.numeric(n), n >= 1)
stopifnot(length(n) == 1, is.integer(n), n >= 1)

## Minimium of all known settings (default)
print(availableCores(which = "min"))
Expand All @@ -19,12 +19,13 @@ print(availableCores(which = "min"))
print(availableCores(which = "max"))

## All known settings
print(availableCores(na.rm = FALSE, which = "all"))
ns <- availableCores(na.rm = FALSE, which = "all")
stopifnot(length(ns) >= 1, is.integer(ns), all(is.na(ns) | ns >= 0L))

## System settings
n <- availableCores(methods = "system")
print(n)
stopifnot(length(n) == 1, is.numeric(n), is.finite(n), n >= 1)
stopifnot(length(n) == 1, is.integer(n), n >= 1)

## Predefined ones for known cluster schedulers
print(availableCores(methods = "PBS"))
Expand Down

0 comments on commit 5ddcd0d

Please sign in to comment.