Skip to content

Commit 7a7f956

Browse files
author
Vasileios Karakasis
authored
Merge pull request #1423 from teojgo/bugfix/use_and_constraint_combine
[bugfix] Use '&' to combine Slurm constraints
2 parents 55c33e2 + 8e37f74 commit 7a7f956

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

cscs-checks/system/slurm/slurm.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def __init__(self):
100100
self.sanity_patterns = sn.assert_found(
101101
r'error: You have to specify, at least, what sort of node you '
102102
r'need: -C gpu for GPU enabled nodes, or -C mc for multicore '
103-
r'nodes.', self.stderr)
103+
r'nodes.|ERROR: you must specify -C with one of the following: '
104+
r'mc,gpu,storage', self.stderr)
104105

105106

106107
@rfm.simple_test
@@ -175,11 +176,8 @@ def __init__(self):
175176
@rfm.run_before('run')
176177
def set_slurm_constraint(self):
177178
cabinet = self.cabinets.get(self.current_partition.fullname)
178-
constraint = f'--constraint={self.current_partition.name}'
179179
if cabinet:
180-
constraint += f'&{cabinet}'
181-
182-
self.job.options += [constraint]
180+
self.job.options += [f'--constraint={cabinet}']
183181

184182

185183
@rfm.simple_test

docs/manpage.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,16 @@ Options controlling job submission
352352
Any job options specified with this command-line option will be emitted after any job options specified in the :js:attr:`access` system partition configuration parameter.
353353

354354
Especially for the Slurm backends, constraint options, such as ``-J constraint=value``, ``-J C=value``, ``-J --constraint=value`` or ``-J -C=value``, are going to be combined with any constraint options specified in the :js:attr:`access` system partition configuration parameter.
355-
For example, if ``-C x`` is specified in the :js:attr:`access` and ``-J C=y`` is passed to the command-line, ReFrame will pass ``-C x,y`` as a constraint to the scheduler.
355+
For example, if ``-C x`` is specified in the :js:attr:`access` and ``-J C=y`` is passed to the command-line, ReFrame will pass ``-C x&y`` as a constraint to the scheduler.
356356
Notice, however, that if constraint options are specified through multiple :option:`-J` options, only the last one will be considered.
357357
If you wish to completely overwrite any constraint options passed in :js:attr:`access`, you should consider passing explicitly the Slurm directive with ``-J '#SBATCH --constraint=new'``.
358358

359359
.. versionchanged:: 3.0
360360
This option has become more flexible.
361361

362+
.. versionchanged:: 3.1
363+
Use ``&`` to combine constraints.
364+
362365
------------------------
363366
Flexible node allocation
364367
------------------------

reframe/core/schedulers/slurm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def emit_preamble(self, job):
214214

215215
if constraints:
216216
preamble.append(
217-
self._format_option(','.join(constraints), '--constraint={0}')
217+
self._format_option('&'.join(constraints), '--constraint={0}')
218218
)
219219

220220
preamble.append(self._format_option(hint, '--hint={0}'))
@@ -326,7 +326,7 @@ def filternodes(self, job, nodes):
326326
'available nodes now: %s' % (partitions, len(nodes)))
327327

328328
if constraints:
329-
constraints = set(constraints.strip().split(','))
329+
constraints = set(constraints.strip().split('&'))
330330
nodes = {n for n in nodes if n.active_features >= constraints}
331331
getlogger().debug(
332332
'flex_alloc_nodes: filtering nodes by constraint(s) %s: '

unittests/test_schedulers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,13 @@ def test_no_empty_lines_in_preamble(minimal_job):
372372

373373
def test_combined_access_constraint(make_job, slurm_only):
374374
job = make_job(sched_access=['--constraint=c1'])
375-
job.options = ['-C c2,c3']
375+
job.options = ['-C c2&c3']
376376
prepare_job(job)
377377
with open(job.script_filename) as fp:
378378
script_content = fp.read()
379379

380-
assert re.search(r'(?m)--constraint=c1,c2,c3$', script_content)
381-
assert re.search(r'(?m)--constraint=(c1|c2,c3)$', script_content) is None
380+
assert re.search(r'(?m)--constraint=c1&c2&c3$', script_content)
381+
assert re.search(r'(?m)--constraint=(c1|c2&c3)$', script_content) is None
382382

383383

384384
def test_combined_access_multiple_constraints(make_job, slurm_only):
@@ -388,7 +388,7 @@ def test_combined_access_multiple_constraints(make_job, slurm_only):
388388
with open(job.script_filename) as fp:
389389
script_content = fp.read()
390390

391-
assert re.search(r'(?m)--constraint=c1,c3$', script_content)
391+
assert re.search(r'(?m)--constraint=c1&c3$', script_content)
392392
assert re.search(r'(?m)--constraint=(c1|c2|c3)$', script_content) is None
393393

394394

@@ -781,7 +781,7 @@ def test_flex_alloc_valid_constraint_opt(make_flexible_job):
781781

782782
def test_flex_alloc_valid_multiple_constraints(make_flexible_job):
783783
job = make_flexible_job('all')
784-
job.options = ['-C f1,f3']
784+
job.options = ['-C f1&f3']
785785
prepare_job(job)
786786
assert job.num_tasks == 4
787787

@@ -808,7 +808,7 @@ def test_flex_alloc_valid_multiple_partitions(make_flexible_job):
808808

809809
def test_flex_alloc_valid_constraint_partition(make_flexible_job):
810810
job = make_flexible_job('all')
811-
job.options = ['-C f1,f2', '--partition=p1,p2']
811+
job.options = ['-C f1&f2', '--partition=p1,p2']
812812
prepare_job(job)
813813
assert job.num_tasks == 4
814814

@@ -867,7 +867,7 @@ def test_flex_alloc_exclude_nodes_opt(make_flexible_job):
867867
def test_flex_alloc_no_num_tasks_per_node(make_flexible_job):
868868
job = make_flexible_job('all')
869869
job.num_tasks_per_node = None
870-
job.options = ['-C f1,f2', '--partition=p1,p2']
870+
job.options = ['-C f1&f2', '--partition=p1,p2']
871871
prepare_job(job)
872872
assert job.num_tasks == 1
873873

@@ -888,15 +888,15 @@ def test_flex_alloc_maintenance_nodes(make_flexible_job):
888888

889889
def test_flex_alloc_not_enough_nodes_constraint_partition(make_flexible_job):
890890
job = make_flexible_job('all')
891-
job.options = ['-C f1,f2', '--partition=p1,p2']
891+
job.options = ['-C f1&f2', '--partition=p1,p2']
892892
job.num_tasks = -8
893893
with pytest.raises(JobError):
894894
prepare_job(job)
895895

896896

897897
def test_flex_alloc_enough_nodes_constraint_partition(make_flexible_job):
898898
job = make_flexible_job('all')
899-
job.options = ['-C f1,f2', '--partition=p1,p2']
899+
job.options = ['-C f1&f2', '--partition=p1,p2']
900900
job.num_tasks = -4
901901
prepare_job(job)
902902
assert job.num_tasks == 4

0 commit comments

Comments
 (0)