From c8aaed1e30bafd159621145bb9ad972d89a7c762 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Fri, 30 May 2014 10:14:57 -0700
Subject: [PATCH] Allocate step part of job's allocation

If a job allocates whole nodes (with --core-spec or --exclusive
option) and launches a step within that allocation all in a single
command (the srun creates the allocation and step at the same time)
and requests a specific CPU count (e.g. "-ntasks=# --cpus-per-task=#")
then allocate the job step only the requested CPU count, which may
be less than the job's allocation.
Bug 843
---
 src/srun/libsrun/srun_job.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/srun/libsrun/srun_job.c b/src/srun/libsrun/srun_job.c
index ca33725d6b4..5ef5ad8330f 100644
--- a/src/srun/libsrun/srun_job.c
+++ b/src/srun/libsrun/srun_job.c
@@ -578,13 +578,20 @@ extern void create_srun_job(srun_job_t **p_job, bool *got_alloc,
 		}
 		job = job_create_allocation(resp);
 
-		opt.exclusive = false;	/* not applicable for this step */
 		opt.time_limit = NO_VAL;/* not applicable for step, only job */
 		xfree(opt.constraints);	/* not applicable for this step */
 		if (!opt.job_name_set_cmd && opt.job_name_set_env) {
 			/* use SLURM_JOB_NAME env var */
 			opt.job_name_set_cmd = true;
 		}
+		if ((opt.core_spec_set || opt.exclusive) && opt.cpus_set) {
+			/* Step gets specified CPU count, which may only part
+			 * of the job allocation. */
+			opt.exclusive = true;
+		} else {
+			/* Step gets all CPUs in the job allocation. */
+			opt.exclusive = false;
+		}
 
 		/*
 		 *  Become --uid user
-- 
GitLab