From a58a25ca830fce60dd3c3bae36be3eeb424d59b5 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Wed, 8 Jan 2003 23:59:15 +0000
Subject: [PATCH] Pass max_nodes as NO_VAL if not explicitly set (formerly was
 set to min_nodes). This permits node count to rise as needed for processor
 count.

---
 src/srun/opt.c  | 17 ++++++++++++-----
 src/srun/srun.c |  6 ++++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/srun/opt.c b/src/srun/opt.c
index 741bde02887..b31edc41b6c 100644
--- a/src/srun/opt.c
+++ b/src/srun/opt.c
@@ -429,7 +429,7 @@ _verify_node_count(const char *arg, int *min_nodes, int *max_nodes)
 
 	val1 = strtol(arg, &end_ptr, 10);
 	if (end_ptr[0] == '\0') {
-		*min_nodes = *max_nodes = val1;
+		*min_nodes = val1;
 		return true;
 	}
 
@@ -565,7 +565,7 @@ static void _opt_default()
 	opt.cpus_per_task = 1;
 	opt.cpus_set = false;
 	opt.min_nodes = 1;
-	opt.max_nodes = 1;
+	opt.max_nodes = 0;
 	opt.nodes_set = false;
 	opt.time_limit = -1;
 	opt.partition = NULL;
@@ -978,7 +978,8 @@ _opt_verify(poptContext optctx)
 			verified = false;
 		}
 
-		if ((opt.min_nodes <= 0) || (opt.max_nodes <= 0)) {
+		if ((opt.min_nodes <= 0) || (opt.max_nodes < 0) || 
+		    (opt.max_nodes && (opt.min_nodes > opt.max_nodes))) {
 			error("%s: invalid number of nodes (-N %d-%d)\n",
 			      opt.progname, opt.min_nodes, opt.max_nodes);
 			verified = false;
@@ -997,7 +998,10 @@ _opt_verify(poptContext optctx)
 				      "nodes, setting nnodes to %d", 
 				      opt.nprocs, opt.min_nodes, 
 				      opt.min_nodes);
-				opt.min_nodes = opt.max_nodes = opt.nprocs;
+				opt.min_nodes = opt.nprocs;
+				if (opt.max_nodes && 
+				    (opt.min_nodes > opt.max_nodes))
+					opt.max_nodes = opt.min_nodes;
 			}
 
 		} /* else if (opt.nprocs_set && !opt.nodes_set) */
@@ -1144,7 +1148,10 @@ void _opt_list()
 	info("cwd            : %s", opt.cwd);
 	info("nprocs         : %d", opt.nprocs);
 	info("cpus_per_task  : %d", opt.cpus_per_task);
-	info("nodes          : %d-%d", opt.min_nodes, opt.max_nodes);
+	if (opt.max_nodes)
+		info("nodes          : %d-%d", opt.min_nodes, opt.max_nodes);
+	else
+		info("nodes          : %d", opt.min_nodes);
 	info("partition      : %s",
 	     opt.partition == NULL ? "default" : opt.partition);
 	info("job name       : `%s'", opt.job_name);
diff --git a/src/srun/srun.c b/src/srun/srun.c
index ac64bfaebf4..8e08a80ff2b 100644
--- a/src/srun/srun.c
+++ b/src/srun/srun.c
@@ -260,7 +260,8 @@ _allocate_nodes(void)
 	job.exc_nodes      = opt.exc_nodes;
 	job.partition      = opt.partition;
 	job.min_nodes      = opt.min_nodes;
-	job.max_nodes      = opt.max_nodes;
+	if (opt.max_nodes)
+		job.max_nodes      = opt.max_nodes;
 	job.num_tasks      = opt.nprocs;
 	job.user_id        = opt.uid;
 	if (opt.mincpus > -1)
@@ -496,7 +497,8 @@ _run_batch_job(void)
 		job.num_procs      = opt.nprocs * opt.cpus_per_task;
 
 	job.min_nodes      = opt.min_nodes;
-	job.max_nodes      = opt.max_nodes;
+	if (opt.max_nodes)
+		job.max_nodes      = opt.max_nodes;
 
 	job.num_tasks      = opt.nprocs;
 
-- 
GitLab