Skip to content

Commit

Permalink
shell: support more mustache tags
Browse files Browse the repository at this point in the history
Problem: The job shell supports a limited set of mustache tags.

Expand the set of supported tags, including:

 - {{nnodes}} and {{size}} for the total node and task count
 - A set of node.* tags including:
  - {{node.id}}: index of this shell relative to job
  - {{node.ntasks}}: number of tasks local to this node
  - {{node.name}}: hostname
  - {{node.ncores}}: number of allocated cores on this node
  - {{node.ngpus}}: number of allocated gpus on this node
  - {{node.taskids}: task idset, e.g. 0-3
  - {{node.coreids}}: core idset, e.g. "0-3"
  - {{node.gpuids}}: gpu idset e.g. "0"
  • Loading branch information
grondo committed Dec 16, 2024
1 parent d96e379 commit f5ecedc
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,51 @@ static int mustache_render_task (flux_shell_t *shell,
return 0;
}

/* Render node specific tags:
* - {{node.id}}: index of this shell relative to job
* - {{node.ntasks}}: number of tasks local to this node
* - {{node.name}}: hostname
* - {{node.ncores}}: number of allocated cores on this node
* - {{node.ngpus}}: number of allocated gpus on this node
* - {{node.taskids}: task idset, e.g. 0-3
* - {{node.coreids}}: core idset, e.g. "0-3"
* - {{node.gpuids}}: gpu idset e.g. "0"
*/
static int mustache_render_node (flux_shell_t *shell,

Check warning on line 1144 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1144

Added line #L1144 was not covered by tests
const char *name,
FILE *fp)
{
const char *s;
int rc = -1;

Check warning on line 1149 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1148-L1149

Added lines #L1148 - L1149 were not covered by tests

s = name + 5; /* forward past 'node.' */
if (streq (s, "id"))
rc = fprintf (fp, "%d", shell->info->rankinfo.nodeid);
else if (streq (s, "ntasks"))
rc = fprintf (fp, "%d", shell->info->rankinfo.ntasks);
else if (streq (s, "ncores"))
rc = fprintf (fp, "%d", shell->info->rankinfo.ncores);
else if (streq (s, "name"))
rc = fputs (shell->hostname, fp);
else if (streq (s, "taskids")) {
char *ids = idset_encode (shell->info->taskids, IDSET_FLAG_RANGE);
if (ids)
rc = fputs (ids, fp);
ERRNO_SAFE_WRAP (free, ids);

Check warning on line 1164 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1151-L1164

Added lines #L1151 - L1164 were not covered by tests
}
else if (streq (s, "coreids"))
rc = fputs (shell->info->rankinfo.cores, fp);
else if (streq (s, "gpuids"))
rc = fputs (shell->info->rankinfo.gpus, fp);

Check warning on line 1169 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1166-L1169

Added lines #L1166 - L1169 were not covered by tests
else {
errno = ENOENT;
return -1;

Check warning on line 1172 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1171-L1172

Added lines #L1171 - L1172 were not covered by tests
}
if (rc < 0)
shell_log_errno ("memstream write failed for %s", name);

Check warning on line 1175 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1174-L1175

Added lines #L1174 - L1175 were not covered by tests
return rc;
}

static int mustache_cb (FILE *fp, const char *name, void *arg)
{
int rc = -1;
Expand All @@ -1150,8 +1195,14 @@ static int mustache_cb (FILE *fp, const char *name, void *arg)
return mustache_render_jobid (shell, name, fp);
if (streq (name, "name"))
return mustache_render_name (shell, name, fp);
if (streq (name, "nnodes"))
return fprintf (fp, "%d", shell->info->shell_size);

Check warning on line 1199 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1199

Added line #L1199 was not covered by tests
if (streq (name, "size"))
return fprintf (fp, "%d", shell->info->total_ntasks);

Check warning on line 1201 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1201

Added line #L1201 was not covered by tests
if (strstarts (name, "task."))
return mustache_render_task (shell, name, fp);

Check warning on line 1203 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1203

Added line #L1203 was not covered by tests
if (strstarts (name, "node."))
return mustache_render_node (shell, name, fp);

Check warning on line 1205 in src/shell/shell.c

View check run for this annotation

Codecov / codecov/patch

src/shell/shell.c#L1205

Added line #L1205 was not covered by tests

if (snprintf (topic,
sizeof (topic),
Expand Down

0 comments on commit f5ecedc

Please sign in to comment.