From 1eb32c58022c7580bd07a65fc81b3bfba4f714d4 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 10 Jan 2003 01:39:04 +0000
Subject: [PATCH] Set task count based upon actual cpu count in allocation
 (with min-max nodes) and cpus_per_task option.

---
 src/srun/srun.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/srun/srun.c b/src/srun/srun.c
index b898cec846e..e67b563d09b 100644
--- a/src/srun/srun.c
+++ b/src/srun/srun.c
@@ -86,6 +86,7 @@ typedef resource_allocation_and_run_response_msg_t alloc_run_resp;
  * forward declaration of static funcs
  */
 static allocation_resp	*_allocate_nodes(void);
+static int 		 _compute_task_count(allocation_resp *resp);
 static void              _print_job_information(allocation_resp *resp);
 static void		 _create_job_step(job_t *job);
 static void		 _sig_kill_alloc(int signum);
@@ -329,11 +330,25 @@ _allocate_nodes(void)
 		sigaction(SIGINT, &old_action, NULL);
 	}
 	if (!opt.nprocs_set)	/* can vary by min-max node count */
-		opt.nprocs = resp->node_cnt;
+		opt.nprocs = _compute_task_count(resp);
 
 	return resp;
 }
 
+static int _compute_task_count(allocation_resp *resp)
+{
+	int i, cnt = 0;
+
+	if (opt.cpus_set) {
+		for (i=0; i<resp->num_cpu_groups; i++)
+			cnt += (resp->cpu_count_reps[i] * 
+				(resp->cpus_per_node[i]/opt.cpus_per_task));
+	} 
+	if (cnt < resp->node_cnt)
+		cnt = resp->node_cnt;
+	return cnt;
+}
+
 static void
 _sig_kill_alloc(int signum)
 {
-- 
GitLab