Skip to content

Commit 650223d

Browse files
authored
Merge pull request #5756 from grondo/shell-broker_rank
shell: fix incorrect values returned from `flux_shell_get_rank_info(3)`
2 parents 51823b8 + 8dded1a commit 650223d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/shell/shell.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ static json_t *flux_shell_get_rank_info_object (flux_shell_t *shell, int rank)
530530
char key [128];
531531
char *taskids = NULL;
532532
struct taskmap *map;
533+
struct rcalc_rankinfo rankinfo;
533534

534535
if (!shell->info)
535536
return NULL;
@@ -551,13 +552,16 @@ static json_t *flux_shell_get_rank_info_object (flux_shell_t *shell, int rank)
551552
if (!(taskids = get_rank_task_idset (map, rank)))
552553
return NULL;
553554

555+
if (rcalc_get_nth (shell->info->rcalc, rank, &rankinfo) < 0)
556+
return NULL;
557+
554558
o = json_pack_ex (&error, 0, "{ s:i s:i s:s s:{s:s s:s?}}",
555-
"broker_rank", rank,
559+
"broker_rank", rankinfo.rank,
556560
"ntasks", taskmap_ntasks (map, rank),
557561
"taskids", taskids,
558562
"resources",
559-
"cores", shell->info->rankinfo.cores,
560-
"gpus", shell->info->rankinfo.gpus);
563+
"cores", rankinfo.cores,
564+
"gpus", rankinfo.gpus);
561565
free (taskids);
562566

563567
if (o == NULL)

t/t2603-job-shell-initrc.t

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_description='Test flux-shell initrc.lua implementation'
44

55
. `dirname $0`/sharness.sh
66

7-
test_under_flux 1
7+
test_under_flux 4
88

99
FLUX_SHELL="${FLUX_BUILD_DIR}/src/shell/flux-shell"
1010

@@ -280,4 +280,25 @@ test_expect_success 'flux-shell: initrc: shell.die function works' '
280280
> ${name}.log 2>&1 &&
281281
grep "FATAL: test: shell.die" ${name}.log
282282
'
283+
test_expect_success MULTICORE 'flux-shell: initrc: shell.rankinfo reports broker_rank' '
284+
name=shell.rankinfo.broker_rank &&
285+
cat >${name}.lua <<-EOF &&
286+
ri0 = shell.get_rankinfo(0)
287+
ri1 = shell.get_rankinfo(1)
288+
if ri0.broker_rank ~= 1 or ri1.broker_rank ~= 3 then
289+
shell.log ("rankinfo(0).broker_rank = "
290+
..shell.get_rankinfo(0).broker_rank)
291+
shell.log ("rankinfo(1).broker_rank = "
292+
..shell.get_rankinfo(1).broker_rank)
293+
shell.die ("rankinfo.broker_rank incorrect!")
294+
end
295+
if ri0.ntasks ~= 2 or ri1.ntasks ~= 1 then
296+
shell.die ("got ri[0].ntasks = "..ri0.ntasks
297+
.." ri[1].ntasks = "..ri1.ntasks)
298+
end
299+
EOF
300+
flux run -N2 -n3 --requires=rank:1,3 \
301+
-o verbose -o initrc=${name}.lua true
302+
'
303+
flux job info $(flux job last) R
283304
test_done

0 commit comments

Comments
 (0)