From a0a76760b5ed4dd257a1c6b448ecab7351acd602 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Wed, 6 Aug 2003 23:14:15 +0000
Subject: [PATCH] Change job's node count from counting bitmap entries to using
 hostlist entry counting function. As a job is completing the bitmap gets
 cleared as nodes complete, resulting in incorrect values.

---
 src/squeue/print.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/squeue/print.c b/src/squeue/print.c
index 0cc5ca7e9a6..04e4bef2c05 100644
--- a/src/squeue/print.c
+++ b/src/squeue/print.c
@@ -42,6 +42,7 @@
 static int _filter_job(job_info_t * job);
 static int _filter_step(job_step_info_t * step);
 static int _get_node_cnt(job_info_t * job);
+int _nodes_in_list(char *node_list);
 static int _print_str(char *str, int width, bool right, bool cut_output);
 
 /*****************************************************************************
@@ -553,25 +554,28 @@ int _print_job_num_nodes(job_info_t * job, int width, bool right_justify,
 
 int _get_node_cnt(job_info_t * job)
 {
-	int node_cnt = 0;
+	int node_cnt = 0, round;
 	uint16_t base_job_state = job->job_state & (~JOB_COMPLETING);
 
 	if (base_job_state == JOB_PENDING) {
-		int *current = job->req_node_inx, round;
-		for ( ; *current != -1; current +=2)
-			node_cnt += current[1] - current[0] + 1;
+		node_cnt = _nodes_in_list(job->req_nodes);
 		node_cnt = MAX(node_cnt, job->num_nodes);
 		round  = job->num_procs + params.max_procs - 1;
 		round /= params.max_procs;	/* round up */
 		node_cnt = MAX(node_cnt, round);
-	} else {
-		int *current = job->node_inx;
-		for ( ; *current != -1; current +=2)
-			node_cnt += current[1] - current[0] + 1;
-	}
+	} else
+		node_cnt = _nodes_in_list(job->nodes);
 	return node_cnt;
 }
 
+int _nodes_in_list(char *node_list)
+{
+	hostset_t host_set = hostset_create(node_list);
+	int count = hostset_count(host_set);
+	hostset_destroy(host_set);
+	return count;
+}
+
 int _print_job_shared(job_info_t * job, int width, bool right_justify, 
 		      char* suffix)
 {
-- 
GitLab