From ed3bbd4718a6a22a46b178732ed1ff072c29ceb8 Mon Sep 17 00:00:00 2001 From: Nick-Eagles Date: Thu, 19 Oct 2023 13:40:10 -0400 Subject: [PATCH] Properly handle down nodes, where memory is reported as N/A instead of 0 --- R/partition_info.R | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/R/partition_info.R b/R/partition_info.R index 109ac78..7de4659 100644 --- a/R/partition_info.R +++ b/R/partition_info.R @@ -38,9 +38,10 @@ partition_info <- function(partition = "shared", all_nodes = FALSE) { # Grab info about CPUs and memory with 'sinfo' "sinfo -N -O 'PartitionName,NodeList:50,FreeMem,AllocMem,Memory,StateLong,CPUsState'", # Properly delimit columns by "|" - "sed -E 's%[ /\t]+%|%g'", + "sed -E 's%[ \t]+%|%g'", + "sed -E 's%([0-9]+)/%\\1|%g'", # Use better column names for CPU-related columns - "sed 's%CPUS(A|I|O|T)%ALLOC_CPUS|INACTIVE_CPUS|OTHER_CPUS|TOTAL_CPUS%'", + "sed 's%CPUS(A/I/O/T)%ALLOC_CPUS|INACTIVE_CPUS|OTHER_CPUS|TOTAL_CPUS%'", # Remove trailing delimiter "sed 's%|$%%'", sep = " | " @@ -48,7 +49,12 @@ partition_info <- function(partition = "shared", all_nodes = FALSE) { part_df <- read.csv(text = system(command, intern = TRUE), sep = "|") |> as_tibble() |> - mutate(PARTITION = factor(PARTITION)) + mutate( + PARTITION = factor(PARTITION), + # For nodes that are down, free memory is reported as "N/A", but + # really no memory is free and therefore 0 is appropriate + FREE_MEM = as.integer(ifelse(FREE_MEM == "N/A", 0, FREE_MEM)) + ) # Subset by partition if not null if (!is.null(partition)) {