Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# clusters (development version)

* Inside a Slurm job (`.slurmAllocation()` non-NULL) the host headroom is not applied: no `options(clusters.memoryHeadroom)`, no `options(clusters.keepFreeCores)` and none of `freeCores()`'s `fraction` (all the job's CPUs are free, whether or not it is the whole node). A job whose memory limit cannot be read keeps the headroom, since its memory is then the node's. The job owns its allocation, so the headroom only wasted it (GPSC 2026-11-14: a 64-CPU, 454G whole-node job with 437 GB free capped 10 GB workers at 39, and a 40-worker fit waited over an hour). `.limitToJob()` flags the probe (`in_slurm_job`, not a ledger column), which `.fitCapacity()` reads, so `reserveCapacity()` follows too. Outside Slurm nothing changes.

* A fit no longer reads and rewrites the shared `hostSpeed.rds` and `fitMemory.rds` after every generation, which took 2.9 s with all workers idle at 367k rows (8 s at a full 30-day window; 0.03 s on an empty file). `DEoptimIterative()` keeps its records in memory and writes them at each rebalance (`options(clusters.rebalanceEvery)`, default 100 generations), which reads them, and when the fit ends, under the same lock; the files, columns and record semantics are unchanged, so other versions keep sharing them. A fit that is killed loses the records since its last write.

* `plan_psock_min()` mirrors every library of `libPath` (or `.libPaths()`) to the other hosts, in order, not only the first; R's own library is skipped. A single `libPath` behaves as before. A worker's `.libPaths()` now starts with those libraries, in order; the per-user library (`R_LIBS_USER`) comes after them, not first, so what is installed there no longer shadows the run's libraries.
Expand Down
2 changes: 1 addition & 1 deletion R/clusterSetup.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' @param runName The `runName` the fit will be given in [DEoptimIterative()]. A host gets at most as many
#' workers as its free memory holds, at the memory per worker that fit recorded the last time it ran; see
#' [plan_psock_min()] for what is used without a record (`options(clusters.workerMemoryGB)`, unset: no cap).
#' Hosts keep `options(clusters.memoryHeadroom)` (default 0.1) of their memory free. When memory leaves
#' Hosts keep `options(clusters.memoryHeadroom)` (default 0.1) of their memory free (none inside a Slurm job, whose allocation is its own). When memory leaves
#' fewer workers than `nCoresNeeded`, the cluster is built smaller (with a message naming the hosts) and
#' `NP` follows the workers.
#' @param controlArgs Named list of further [DEoptim::DEoptim.control()] settings (for example
Expand Down
27 changes: 20 additions & 7 deletions R/estimateCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#' run fastest ([.speedAllocate()]: the hardware model [.workerSpeed()] times each host's measured speed,
#' [.hostSpeedFactor()]), and optionally launches the final cluster with the computed worker counts.
#' Every host keeps `options(clusters.keepFreeCores)` (default 2) of its threads free of all workers and
#' other load, and `options(clusters.memoryHeadroom)` (default 0.1) of its memory; a running cluster asks
#' other load, and `options(clusters.memoryHeadroom)` (default 0.1) of its memory (inside a Slurm job, which owns its
#' CPUs and memory, keeps neither when its memory limit is known: all its CPUs and memory are free); a running cluster asks
#' again by the same rule every `options(clusters.rebalanceEvery)` generations (see [.rebalanceFn()]).
#'
#' This is intentionally minimal—no `master` argument, no diagnostics or fallbacks.
Expand Down Expand Up @@ -44,7 +45,8 @@
#' `options(clusters.workerMemoryGB)` (another fit's record is never used); when that is unset (the
#' default) no host is capped by memory. For FireSense DEoptim workers 14 fits: peak memory was median 4.5 GB, 90th percentile about
#' 6.5 GB, maximum 14.1 GB (457 workers on 15 hosts, 2026-10-09).
#' Every host keeps `options(clusters.memoryHeadroom)` (default 0.1) of its memory free.
#' Every host keeps `options(clusters.memoryHeadroom)` (default 0.1) of its memory free, except inside a Slurm job,
#' which keeps none (its allocation is its own).
#'
#' @return A list with:
#' - `probe`: per-host capacity & load,
Expand Down Expand Up @@ -488,7 +490,7 @@ plan_psock_min <- function(
loadavg = attr(freeC, "loadavg"),
mem_available_gb = tryCatch(.procMemoryGB("MemAvailable", "/proc/meminfo"), error = function(e) NA_real_),
mem_total_gb = tryCatch(.procMemoryGB("MemTotal", "/proc/meminfo"), error = function(e) NA_real_)
), job, systemCores = attr(freeC, "maxCores"))
), job)
}

## The node table: one row per host from what each said of itself (`caps`, .probeHost()'s lists)
Expand All @@ -506,6 +508,7 @@ plan_psock_min <- function(
loadavg_15 = unname(cap$loadavg["15min"]),
mem_available_gb = if (is.null(cap$mem_available_gb)) NA_real_ else cap$mem_available_gb,
mem_total_gb = if (is.null(cap$mem_total_gb)) NA_real_ else cap$mem_total_gb,
in_slurm_job = isTRUE(cap$inSlurmJob), # see .limitToJob(); not a ledger column
stringsAsFactors = FALSE
)
}, hosts, caps))
Expand All @@ -516,7 +519,7 @@ plan_psock_min <- function(
## workers go within these cores is .speedAllocate()'s, by speed.
##
## Cores: the probed free cores, less what other clusters booked (see freeCoresLessReserved()), and never
## more than the host's threads less `getOption("clusters.keepFreeCores", 2)` less `busy`, the workers already
## more than the host's threads less .keepFreeCores() (none in a Slurm job) less `busy`, the workers already
## on the host: other clusters' bookings or the load average, whichever is larger. That cap is hard, whatever
## the load window or the reservations say (2026-10-13: load that no cluster had booked was discounted by
## freeCores()'s fraction only, so a 16-thread host with 10 of other load could still be given 5 workers).
Expand All @@ -526,7 +529,7 @@ plan_psock_min <- function(
##
## Memory limits the cores too, when the memory per worker is known (`memPerWorkerGB`, see
## .memPerWorkerGB(); one number, or `c(median, max)`): a host keeps `getOption("clusters.memoryHeadroom", 0.1)`
## of its memory free, and its workers are at most the largest n with `(n - 1) * median + max <= available
## of its memory free (none inside a Slurm job, which owns its allocation), and its workers are at most the largest n with `(n - 1) * median + max <= available
## memory - headroom` (see .memBudgetGB()): what the host uses now plus the new workers stays within 0.9 of its memory. Available memory is the probed MemAvailable, less what other
## builds booked and their workers have not yet grown into (see freeCoresLessReserved()), plus what `own`
## workers use. `ram_lost` is the cores memory took away.
Expand Down Expand Up @@ -561,7 +564,7 @@ plan_psock_min <- function(
## the hard cap: every worker on the host, this cluster's and all other load, within the threads less the
## cores kept for the host's other users
if (!is.null(nodes$cores_total)) {
cap <- pmax(as.numeric(nodes$cores_total) - getOption("clusters.keepFreeCores", 2) - nodes$busy, 0)
cap <- pmax(as.numeric(nodes$cores_total) - .keepFreeCores(nodes) - nodes$busy, 0)
cap[is.na(cap)] <- Inf
nodes$free_est <- pmin(nodes$free_est, cap)
}
Expand All @@ -577,7 +580,8 @@ plan_psock_min <- function(
nodes$speedFactor <- .hostSpeedFactor(nodes, speeds, beta = beta)
nodes$ram_lost <- 0
if (useMemory) {
headroom <- getOption("clusters.memoryHeadroom", 0.1) * as.numeric(nodes$mem_total_gb)
## a host that is a Slurm job's own keeps none: its cgroup enforces the memory (see .limitToJob())
headroom <- ifelse(.inSlurmJob(nodes), 0, getOption("clusters.memoryHeadroom", 0.1)) * as.numeric(nodes$mem_total_gb)
byMemory <- .memWorkersFitting(nodes$mem_free_gb - headroom, mem)
capped <- !is.na(byMemory) & byMemory < floor(nodes$free_est) # a host that cannot say is not capped
nodes$ram_lost[capped] <- floor(nodes$free_est[capped]) - byMemory[capped]
Expand All @@ -592,6 +596,15 @@ plan_psock_min <- function(
nodes
}

## Which hosts (rows of a node table) are a Slurm job's own allocation (see .limitToJob()); FALSE for a table
## without the column (built by tests or an older clusters)
.inSlurmJob <- function(nodes)
if (is.null(nodes$in_slurm_job)) rep(FALSE, NROW(nodes)) else nodes$in_slurm_job %in% TRUE

## The cores each host keeps free of workers for its other users: getOption("clusters.keepFreeCores", 2), none on
## a Slurm job's own allocation, which has no other users
.keepFreeCores <- function(nodes) ifelse(.inSlurmJob(nodes), 0, getOption("clusters.keepFreeCores", 2))

#' How fast each worker on a host runs, relative to one worker alone
#'
#' A worker runs at full speed while the host's workers are no more than its memory modules (`dimms`) and its
Expand Down
6 changes: 3 additions & 3 deletions R/reservations.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ releaseCores <- function(id = NULL, pid = Sys.getpid(),
#' load of 30-35 (2026-10-02). Read as free, that gap was booked by every later build, until hosts
#' with 48 threads carried 50-52 workers. So `free_est` is also capped at `cores_total` less every
#' worker booked on the host, absorbed or not, and less `getOption("clusters.keepFreeCores", 2)` cores
#' left for the host's other users, when `nodes` has `cores_total`.
#' left for the host's other users (none inside a Slurm job), when `nodes` has `cores_total`.
#'
#' Memory is booked the same way. When `nodes` has `mem_free_gb` (the host's `MemAvailable`), each
#' reservation's `memGB` is subtracted by the same unabsorbed share: a new cluster's workers have not grown
Expand Down Expand Up @@ -295,9 +295,9 @@ freeCoresLessReserved <- function(nodes,
nodes$reserved_gb <- reservedGB
}
free <- as.numeric(nodes$free_est) - round(subtract, 3)
## every host keeps getOption("clusters.keepFreeCores", 2) cores for its other users, whatever its load
## every host keeps .keepFreeCores() cores for its other users, whatever its load (none in a Slurm job)
if (!is.null(nodes$cores_total))
free <- pmin(free, as.numeric(nodes$cores_total) - getOption("clusters.keepFreeCores", 2) - reserved)
free <- pmin(free, as.numeric(nodes$cores_total) - .keepFreeCores(nodes) - reserved)
nodes$free_est <- pmax(free, 0)
nodes
}
Expand Down
2 changes: 1 addition & 1 deletion R/reserveCapacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' and a fit placed its workers on a host the predictions had already filled (2026-10-13).
#' `reserveCapacity()` books such a job in the same ledger, under the same caps as a build (`.fitCapacity()`:
#' every worker and other load within the host's threads less `options(clusters.keepFreeCores)`, and memory
#' used plus the job's within `1 - options(clusters.memoryHeadroom)` of the host's), so a build that follows
#' used plus the job's within `1 - options(clusters.memoryHeadroom)` of the host's; neither inside a Slurm job), so a build that follows
#' subtracts the job's cores and memory ([freeCoresLessReserved()]). It waits like a build waits, up to
#' `waitSeconds` (`options(clusters.waitForCores)`), until the whole of `cores` and `memGB` fits on one of
#' the `hosts`, probing every `interval` seconds, and then stops with the shortfall. Among several `hosts`
Expand Down
20 changes: 10 additions & 10 deletions R/slurmAllocation.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
}

## A host's probe (`cap`, as .probeHost() builds it) limited to the job it runs in (`job`, from
## .slurmAllocation()). Memory is the lower of the node's and the job's. Cores: a job given fewer CPUs
## (`cores_total`) than the node has (`systemCores`) shares it, so its CPUs are all free (the cgroup keeps others off
## them; the node's load average is other jobs' and says nothing of them), and the node's load is not
## carried into `busy` (see .fitCapacity()). What the job's own clusters have booked is in the reservations
## ledger, which counts it (see freeCoresLessReserved()). A job given every CPU is the node's: probed as before.
.limitToJob <- function(cap, job, systemCores) {
## .slurmAllocation()). Memory is the lower of the node's and the job's. A job owns its allocation (the cgroup
## enforces its memory and keeps others off its CPUs), so the headroom that protects a shared workstation from
## other users' growth is not applied: every CPU of the job is free, whole node or not (what the job's own
## clusters use is in the reservations ledger, see freeCoresLessReserved(); the load average says nothing more),
## and `inSlurmJob` tells .fitCapacity() to keep no memory headroom, but only when the job's memory limit is known
## (otherwise `mem_total_gb` is the node's, which other jobs may share).
.limitToJob <- function(cap, job) {
if (is.null(job)) return(cap)
## cores_total is parallelly::availableCores(): the job's CPUs, read from Slurm and its cgroup
if (isTRUE(cap$cores_total < systemCores)) {
cap$free_est <- cap$cores_total
cap$loadavg[] <- 0
}
cap$free_est <- cap$cores_total
cap$loadavg[] <- 0
cap$inSlurmJob <- !is.na(job$memLimitGB)
cap$mem_available_gb <- .minKnown(cap$mem_available_gb, job$memAvailableGB)
cap$mem_total_gb <- .minKnown(cap$mem_total_gb, job$memLimitGB)
cap
Expand Down
2 changes: 1 addition & 1 deletion man/clusterSetup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/freeCoresLessReserved.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/plan_psock_min.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/reserveCapacity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading