Skip to content

Commit

Permalink
Allow for unitless memory strings. Not sure why 'sacct' gives these s…
Browse files Browse the repository at this point in the history
…ometimes for MaxRSS (e.g. '0' when something like '0G' is standard for other columns)
  • Loading branch information
Nick-Eagles committed Oct 2, 2023
1 parent b055d77 commit 46fae3c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions R/job_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,24 @@ job_report <- function(job_id) {

# Given a character vector containing an amount of memory (containing
# a numeric piece and unit, e.g. "1.03G"), return a numeric vector
# with the amount in GB (e.g. 1.03).
# with the amount in GB (e.g. 1.03). If a unit is not provided, GB
# are assumed (e.g. '0.12' is a valid input)
parse_memory_str <- function(mem_str) {
# Grab the numeric and character portions of the string. Verify
# one is NA only when the other is (an indirect way of suggesting
# parsing succeeded, and in particular memory units are expected)
coeff <- as.numeric(str_extract(mem_str, "[0-9]+(\\.[0-9]+)?"))
unit <- str_extract(mem_str, "[KMG]$")
unit <- str_extract(mem_str, "[0-9]+(\\.[0-9]+)?([KMGTP]|)$", group = 2)
if (!all(is.na(coeff) == is.na(unit))) {
stop("Failed to parse memory information. This is a slurmjobs bug!")
}

mem_num <- case_when(
unit == "K" ~ coeff / 1e6,
unit == "M" ~ coeff / 1e3,
unit == "G" ~ coeff,
unit %in% c("G", "") ~ coeff,
unit == "T" ~ coeff * 1e3,
unit == "P" ~ coeff * 1e6,
TRUE ~ NA # note this case is impossible
)

Expand Down

0 comments on commit 46fae3c

Please sign in to comment.