From 44fd27941f5ac5e5baa8b740e0dbdb04ae39b7a3 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 17 Jan 2003 19:36:49 +0000
Subject: [PATCH] Fix bug in handling node range with contiguous option.

---
 src/slurmctld/node_scheduler.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/slurmctld/node_scheduler.c b/src/slurmctld/node_scheduler.c
index 65d1215bacd..cc01d77552e 100644
--- a/src/slurmctld/node_scheduler.c
+++ b/src/slurmctld/node_scheduler.c
@@ -59,6 +59,8 @@ static void _add_node_set_info(struct node_set *node_set_ptr,
 static int  _build_node_list(struct job_record *job_ptr, 
 			     struct node_set **node_set_pptr,
 			     int *node_set_size);
+static bool _enough_nodes(int avail_nodes, int rem_nodes, int min_nodes,
+			  int max_nodes);
 static void _filter_nodes_in_set(struct node_set *node_set_ptr,
 				 struct job_details *detail_ptr);
 static int _match_feature(char *seek, char *available);
@@ -410,8 +412,10 @@ _pick_best_quadrics(bitstr_t * bitmap, bitstr_t * req_bitmap,
 		}
 		if (best_fit_nodes == 0)
 			break;
-		if (consecutive && ((best_fit_nodes < rem_nodes)
-				    || (best_fit_cpus < rem_cpus)))
+		if (consecutive && 
+		    ((best_fit_cpus < rem_cpus) ||
+		     (!_enough_nodes(best_fit_nodes, rem_nodes, 
+				     min_nodes, max_nodes))))
 			break;	/* no hole large enough */
 		if (best_fit_req != -1) {
 			/* This collection of nodes includes required ones
@@ -449,7 +453,8 @@ _pick_best_quadrics(bitstr_t * bitmap, bitstr_t * req_bitmap,
 				rem_cpus -= node_record_table_ptr[i].cpus;
 			}
 		}
-		if ((rem_nodes <= 0) && (rem_cpus <= 0)) {
+		if (consecutive || 
+		    ((rem_nodes <= 0) && (rem_cpus <= 0))) {
 			error_code = SLURM_SUCCESS;
 			break;
 		}
@@ -468,6 +473,19 @@ _pick_best_quadrics(bitstr_t * bitmap, bitstr_t * req_bitmap,
 	return error_code;
 }
 
+static bool 
+_enough_nodes(int avail_nodes, int rem_nodes, int min_nodes, int max_nodes)
+{
+	int needed_nodes;
+
+	if (max_nodes)
+		needed_nodes = rem_nodes + min_nodes - max_nodes;
+	else
+		needed_nodes = rem_nodes;
+
+	return(avail_nodes >= needed_nodes);
+}
+
 
 /*
  * _pick_best_nodes - from a weigh order list of all nodes satisfying a 
-- 
GitLab