Skip to content

Commit

Permalink
flux-mini: set ntasks/slots to nnodes when ntasks not set
Browse files Browse the repository at this point in the history
Problem: It is inconvenient to require the specification of both ntasks
and nnodes when a user wants one task/slot per node. Until recently,
it was not possible to handle this in a coherent manner, though, so
the Python Jobspec class and flux-mini commands throw an error whenever
the node count is greater than the number of requested tasks/slots.

Now that node exclusivity can be set in the jobspec, though, it is
possible to set ntasks/slots to the number of nodes (when ntasks is
not explicitly set), by also defaulting the node exclusive flag to
True for this case.

This allows `flux mini run -N4 command` to work consistently regardless
of whether or not the enclosing instance defaults to node exclusive
allocation.

Fixes flux-framework#4228
  • Loading branch information
grondo committed Mar 29, 2022
1 parent 09ce322 commit c2f5786
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/cmd/flux-mini.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ def __init__(self):
"-n",
"--ntasks",
metavar="N",
default="1",
help="Number of tasks to start",
)
self.parser.add_argument(
Expand Down Expand Up @@ -742,6 +741,15 @@ def init_jobspec(self, args):
if not args.command:
raise ValueError("job command and arguments are missing")

# If ntasks not set, then set it to either node count, with
# exclusive flag enabled, or to 1 (the default).
if not args.ntasks:
if args.nodes:
args.ntasks = args.nodes
args.exclusive = True
else:
args.ntasks = 1

# Ensure integer args are converted to int() here.
# This is done because we do not use type=int in argparse in order
# to allow these options to be mutable for bulksubmit:
Expand Down Expand Up @@ -1510,8 +1518,14 @@ def read_script(args):

def init_jobspec(self, args):
# If no script (reading from stdin), then use "flux" as arg[0]

# If number of slots not specified, then set it to node count
# if set, otherwise raise an error.
if not args.nslots:
raise ValueError("Number of slots to allocate must be specified")
if not args.nodes:
raise ValueError("Number of slots to allocate must be specified")
args.nslots = args.nodes
args.exclusive = True

jobspec = JobspecV1.from_batch_command(
script=self.read_script(args),
Expand Down Expand Up @@ -1556,8 +1570,13 @@ def __init__(self):

def init_jobspec(self, args):

# If number of slots not specified, then set it to node count
# if set, otherwise raise an error.
if not args.nslots:
raise ValueError("Number of slots to allocate must be specified")
if not args.nodes:
raise ValueError("Number of slots to allocate must be specified")
args.nslots = args.nodes
args.exclusive = True

jobspec = JobspecV1.from_nest_command(
command=args.COMMAND,
Expand Down

0 comments on commit c2f5786

Please sign in to comment.