Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jobspec: add level 0 support for moldable jobspecs #3944

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/modules/job-list/job_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,32 @@ static int parse_res_level (struct list_ctx *ctx,
{
json_error_t error;
struct res_level res;
json_t *cnt_o = NULL;

res.with = NULL;
/* For jobspec version 1, expect exactly one array element per level.
*/
if (json_unpack_ex (o, &error, 0,
"[{s:s s:i s?o}]",
"[{s:s s:o s?o}]",
"type", &res.type,
"count", &res.count,
"count", &cnt_o,
"with", &res.with) < 0) {
flux_log (ctx->h, LOG_ERR,
"%s: job %ju invalid jobspec: %s",
__FUNCTION__, (uintmax_t)job->id, error.text);
return -1;
}
if (json_is_integer (cnt_o))
res.count = json_integer_value (cnt_o);
else if (json_unpack_ex (cnt_o, &error, 0,
"{s:i}",
"min", &res.count)) {
flux_log (ctx->h, LOG_ERR,
"%s: job %ju invalid count format in jobspec: %s",
__FUNCTION__, (uintmax_t)job->id, error.text);
return -1;
}

*resp = res;
return 0;
}
Expand Down
14 changes: 12 additions & 2 deletions src/shell/jobspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static int parse_res_level (json_t *o,
{
json_error_t loc_error;
struct res_level res;
json_t *cnt_o = NULL;

if (o == NULL) {
set_error (error, "level %d: missing", level);
Expand All @@ -49,13 +50,22 @@ static int parse_res_level (json_t *o,
/* For jobspec version 1, expect exactly one array element per level.
*/
if (json_unpack_ex (o, &loc_error, 0,
"{s:s s:i s?o}",
"{s:s s:o s?o}",
"type", &res.type,
"count", &res.count,
"count", &cnt_o,
"with", &res.with) < 0) {
set_error (error, "level %d: %s", level, loc_error.text);
return -1;
}
if (json_is_integer (cnt_o))
res.count = json_integer_value (cnt_o);
else if (json_unpack_ex (cnt_o, &loc_error, 0,
"{s:i}",
"min", &res.count)) {
set_error (error, "level %d (count): %s", level, loc_error.text);
return -1;
}

*resp = res;
return 0;
}
Expand Down
40 changes: 40 additions & 0 deletions src/shell/test/jobspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ struct input good_input[] = {
"flux jobspec srun hostname (slot->core)",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": 1, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"flux jobspec srun hostname (slot->core[>=1])",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": {\"min\": 1}, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"flux jobspec srun hostname (slot->core[>=1,<=8])",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": {\"min\": 1, \"max\": 8}, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"flux jobspec srun hostname (slot->core[>=1,<=8,oper=+])",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": {\"min\": 1, \"max\": 8, \"operator\": \"+\"}, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"flux jobspec srun hostname (slot->core[>=1,<=8,oper=+,op=2])",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": {\"min\": 1, \"max\": 8, \"operator\": \"+\", \"operand\": 2}, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"flux jobspec srun hostname (slot->core[>=1,<=8,oper=*,op=3])",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": {\"min\": 1, \"max\": 8, \"operator\": \"*\", \"operand\": 3}, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"flux jobspec srun hostname (slot->core[>=1,<=8,oper=^,op=2])",
"{\"tasks\": [{\"slot\": \"task\", \"count\": {\"per_slot\": 1}, \"command\": [\"hostname\"], \"attributes\": {}}], \"attributes\": {\"system\": {\"cwd\": \"/home/garlick/proj/flux-core/src/cmd\"}}, \"version\": 1, \"resources\": [{\"count\": 1, \"with\": [{\"count\": {\"min\": 1, \"max\": 8, \"operator\": \"^\", \"operand\": 2}, \"type\": \"core\"}], \"type\": \"slot\", \"label\": \"task\"}]}",
},
{
"node->socket->slot->core",
"{\"resources\": [{\"type\": \"node\", \"count\": 1, \"with\": [{\"type\": \"socket\", \"count\": 1, \"with\": [{\"type\": \"slot\", \"count\": 1, \"with\": [{\"type\": \"core\", \"count\": 1}], \"label\": \"task\"}]}]}], \"tasks\": [{\"command\": [\"hostname\"], \"slot\": \"task\", \"count\": {\"per_slot\": 1}}], \"attributes\": {\"system\": {\"duration\": 0, \"cwd\": \"/usr/libexec/flux\", \"environment\": {}}}, \"version\": 1}",
Expand All @@ -50,6 +74,14 @@ struct input good_input[] = {
"node->socket->slot->(core[2],gpu)",
"{\"resources\": [{\"type\": \"node\", \"count\": 1, \"with\": [{\"type\": \"socket\", \"count\": 1, \"with\": [{\"type\": \"slot\", \"label\": \"task\", \"count\": 1, \"with\": [{\"type\": \"core\", \"count\": 2}, {\"type\": \"gpu\", \"count\": 1}]}]}]}], \"tasks\": [{\"command\": [\"hostname\"], \"slot\": \"task\", \"count\": {\"per_slot\": 1}}], \"attributes\": {\"system\": {\"duration\": 0, \"cwd\": \"/usr/libexec/flux\", \"environment\": {}}}, \"version\": 1}",
},
{
"node->socket->slot->(core[>=2],gpu[>=1])",
"{\"resources\": [{\"type\": \"node\", \"count\": 1, \"with\": [{\"type\": \"socket\", \"count\": 1, \"with\": [{\"type\": \"slot\", \"label\": \"task\", \"count\": 1, \"with\": [{\"type\": \"core\", \"count\": {\"min\": 2}}, {\"type\": \"gpu\", \"count\": {\"min\": 1}}]}]}]}], \"tasks\": [{\"command\": [\"hostname\"], \"slot\": \"task\", \"count\": {\"per_slot\": 1}}], \"attributes\": {\"system\": {\"duration\": 0, \"cwd\": \"/usr/libexec/flux\", \"environment\": {}}}, \"version\": 1}",
},
{
"node->socket->slot->(core[>=2,<=8],gpu[>=1,<=2])",
"{\"resources\": [{\"type\": \"node\", \"count\": 1, \"with\": [{\"type\": \"socket\", \"count\": 1, \"with\": [{\"type\": \"slot\", \"label\": \"task\", \"count\": 1, \"with\": [{\"type\": \"core\", \"count\": {\"min\": 2, \"max\": 8}}, {\"type\": \"gpu\", \"count\": {\"min\": 1, \"max\": 2}}]}]}]}], \"tasks\": [{\"command\": [\"hostname\"], \"slot\": \"task\", \"count\": {\"per_slot\": 1}}], \"attributes\": {\"system\": {\"duration\": 0, \"cwd\": \"/usr/libexec/flux\", \"environment\": {}}}, \"version\": 1}",
},
{
"node->socket->slot->(gpu,core)",
"{\"resources\": [{\"type\": \"node\", \"count\": 1, \"with\": [{\"type\": \"socket\", \"count\": 1, \"with\": [{\"type\": \"slot\", \"label\": \"task\", \"count\": 1, \"with\": [{\"type\": \"gpu\", \"count\": 1}, {\"type\": \"core\", \"count\": 1}]}]}]}], \"tasks\": [{\"command\": [\"hostname\"], \"slot\": \"task\", \"count\": {\"per_slot\": 1}}], \"attributes\": {\"system\": {\"duration\": 0, \"cwd\": \"/usr/libexec/flux\", \"environment\": {}}}, \"version\": 1}",
Expand All @@ -74,11 +106,19 @@ struct input good_input[] = {
};
struct output good_output[] =
{
{1, 1, 1, -1},
{1, 1, 1, -1},
{1, 1, 1, -1},
{1, 1, 1, -1},
{1, 1, 1, -1},
{1, 1, 1, -1},
{1, 1, 1, -1},
{1, 1, 1, 1},
{30, 30, 3, 15},
{5, 5, 6, -1},
{1, 1, 2, 1},
{1, 1, 2, 1},
{1, 1, 2, 1},
{1, 1, 1, 1},
{1, 1, 2, 1},
{6, 6, 5, 3},
Expand Down