From f78a6a06171483f44f796fcc38f144acbbfd3ec6 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@schedmd.com>
Date: Wed, 23 May 2012 13:25:59 -0700
Subject: [PATCH] BGQ - make it so srun -i<taskid> works correctly

---
 NEWS           |  1 +
 src/srun/opt.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/NEWS b/NEWS
index a2a6adb0536..fad593cca4c 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ documents those changes that are of interest to users and admins.
 =============================
  -- Cray - Improve support for zero compute note resource allocations.
     Partition used can now be configured with no nodes nodes.
+ -- BGQ - make it so srun -i<taskid> works correctly
 
 * Changes in SLURM 2.4.0.rc1
 =============================
diff --git a/src/srun/opt.c b/src/srun/opt.c
index 59352aa5363..cab6ff9d61b 100644
--- a/src/srun/opt.c
+++ b/src/srun/opt.c
@@ -1722,6 +1722,7 @@ static void _opt_args(int argc, char **argv)
 	}
 
 #if defined HAVE_BG_FILES
+	uint32_t taskid = 0;
 	if (!opt.test_only) {
 	 	/* Since we need the opt.argc to allocate the opt.argv array
 		 * we need to do this before actually messing with
@@ -1743,6 +1744,13 @@ static void _opt_args(int argc, char **argv)
 			command_pos += 2;
 		if (_verbose)
 			command_pos += 2;
+		if (opt.ifname) {
+			char *p;
+			taskid = strtoul(opt.ifname, &p, 10);
+			if ((*p == '\0') && ((int) taskid < opt.ntasks)) {
+				command_pos += 2;
+			}
+		}
 		if (opt.runjob_opts) {
 			char *save_ptr = NULL, *tok;
 			char *tmp = xstrdup(opt.runjob_opts);
@@ -1804,6 +1812,11 @@ static void _opt_args(int argc, char **argv)
 			opt.argv[i++]  = xstrdup_printf("%d", _verbose);
 		}
 
+		if (taskid) {
+			opt.argv[i++]  = xstrdup("--stdinrank");
+			opt.argv[i++]  = xstrdup_printf("%u", taskid);
+		}
+
 		if (opt.runjob_opts) {
 			char *save_ptr = NULL, *tok;
 			char *tmp = xstrdup(opt.runjob_opts);
-- 
GitLab