From 1e7a37110004727385a6e71d1e756ca62fe64b43 Mon Sep 17 00:00:00 2001
From: Hongjia Cao <hjcao@nudt.edu.cn>
Date: Wed, 12 Sep 2012 10:44:36 -0700
Subject: [PATCH] Correct srun --no-alloc task layout if task count not a
 multiple of node count

srun: do not allocate resources
cn9
cn9
cn8
cn8
---
 NEWS                           |  2 ++
 src/common/slurm_step_layout.c | 12 ++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 651796b3d77..237da5a1045 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,8 @@ documents those changes that are of interest to users and admins.
     partition name by default.
  -- Make it so the parse_time will return a valid 0 if given epoch time and
     set errno == ESLURM_INVALID_TIME_VALUE on error instead.
+ -- Correct srun --no-alloc logic when node count exceeds node list or task
+    task count is not a multiple of the node count. Work by Hongjia Cao, NUDT.
 
 * Changes in SLURM 2.5.0.pre1
 =============================
diff --git a/src/common/slurm_step_layout.c b/src/common/slurm_step_layout.c
index 495c622b61b..a9f28ed0fdb 100644
--- a/src/common/slurm_step_layout.c
+++ b/src/common/slurm_step_layout.c
@@ -163,7 +163,6 @@ slurm_step_layout_t *fake_slurm_step_layout_create(
 {
 	uint32_t cpn = 1;
 	int cpu_cnt = 0, cpu_inx = 0, i, j;
-	hostlist_t hl = NULL;
 	slurm_step_layout_t *step_layout = NULL;
 
 	if ((node_cnt <= 0) || (task_cnt <= 0 && !cpus_per_node) || !tlist) {
@@ -173,11 +172,6 @@ slurm_step_layout_t *fake_slurm_step_layout_create(
 		return NULL;
 	}
 
-	hl = hostlist_create(tlist);
-	/* make out how many cpus there are on each node */
-	if (task_cnt > 0)
-		cpn = (task_cnt + node_cnt - 1) / node_cnt;
-
 	step_layout = xmalloc(sizeof(slurm_step_layout_t));
 	step_layout->node_list = xstrdup(tlist);
 	step_layout->node_cnt = node_cnt;
@@ -201,6 +195,8 @@ slurm_step_layout_t *fake_slurm_step_layout_create(
 				cpu_cnt = 0;
 			}
 		} else {
+			cpn = ((task_cnt - step_layout->task_cnt) +
+			       (node_cnt - i) - 1) / (node_cnt - i);
 			if (step_layout->task_cnt >= task_cnt) {
 				step_layout->tasks[i] = 0;
 				step_layout->tids[i] = NULL;
@@ -212,7 +208,7 @@ slurm_step_layout_t *fake_slurm_step_layout_create(
 				for (j = 0; j < cpn; j++) {
 					step_layout->tids[i][j] =
 						step_layout->task_cnt++;
-					if(step_layout->task_cnt >= task_cnt) {
+					if (step_layout->task_cnt >= task_cnt) {
 						step_layout->tasks[i] = j + 1;
 						break;
 					}
@@ -220,7 +216,7 @@ slurm_step_layout_t *fake_slurm_step_layout_create(
 			}
 		}
 	}
-	hostlist_destroy(hl);
+
 	return step_layout;
 }
 
-- 
GitLab