Skip to content

Commit 7f0742a

Browse files
cmeesterscoderabbitai[bot]johanneskoester
authored
fix: mpi task settings (#363)
This PR restores former behaviour regarding MPI allowing both `tasks` and `tasks_per_node` to be set. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * MPI warning now appears only when tasks_per_node, nodes, and tasks are all missing. * MPI submissions with missing or conflicting task counts now produce clear errors to prevent ambiguous jobs. * **Improvements** * Enforces sensible minimums for MPI task settings and disallows specifying both per-node and total task counts. * Non-MPI jobs no longer force total-task flags. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Johannes Köster <[email protected]>
1 parent 799f95b commit 7f0742a

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,6 @@ def run_job(self, job: JobExecutorInterface):
341341
"- submitting without. This might or might not work on your cluster."
342342
)
343343

344-
# MPI job
345-
if job.resources.get("mpi", False):
346-
if not job.resources.get("tasks_per_node") and not job.resources.get(
347-
"nodes"
348-
):
349-
self.logger.warning(
350-
"MPI job detected, but no 'tasks_per_node' or 'nodes' "
351-
"specified. Assuming 'tasks_per_node=1'."
352-
"Probably not what you want."
353-
)
354-
355344
exec_job = self.format_job_exec(job)
356345

357346
# and finally the job to execute with all the snakemake parameters

snakemake_executor_plugin_slurm/submit_string.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from snakemake_interface_common.exceptions import WorkflowError
12
from snakemake_executor_plugin_slurm_jobstep import get_cpu_setting
23
from types import SimpleNamespace
34
import shlex
@@ -83,7 +84,36 @@ def get_submit_command(job, params):
8384
else:
8485
# fixes #40 - set ntasks regardless of mpi, because
8586
# SLURM v22.05 will require it for all jobs
86-
call += f" --ntasks={job.resources.get('tasks') or 1}"
87+
# if the job is a MPI job, ntasks will be set later
88+
if not job.resources.get("mpi", False):
89+
call += f" --ntasks={job.resources.get('tasks') or 1}"
90+
91+
# if the job is an MPI job, we need to have some task setting:
92+
if job.resources.get("mpi", False):
93+
if not job.resources.get("tasks_per_node") and not job.resources.get("tasks"):
94+
raise WorkflowError(
95+
"For MPI jobs, please specify either "
96+
"'tasks_per_node' or 'tasks' (at least one is required)."
97+
)
98+
# raise an error if both task settings are used
99+
if job.resources.get("tasks_per_node") and job.resources.get("tasks"):
100+
raise WorkflowError(
101+
"For MPI jobs, please specify either 'tasks_per_node' or 'tasks', "
102+
"but not both."
103+
)
104+
if job.resources.get("tasks_per_node"):
105+
if job.resources.get("tasks_per_node") <= 1:
106+
raise WorkflowError(
107+
"For MPI jobs, 'tasks_per_node' must be greater than 1."
108+
)
109+
call += f" --ntasks-per-node={job.resources.tasks_per_node}"
110+
elif job.resources.get("tasks"):
111+
if job.resources.get("tasks") == 1:
112+
raise WorkflowError("For MPI jobs, 'tasks' must be greater than 1.")
113+
call += f" --ntasks={job.resources.tasks}"
114+
# nodes CAN be set independently of tasks or tasks_per_node
115+
# this is at a user's discretion. The nodes flag might already
116+
# be set above, if the user specified it.
87117

88118
# we need to set cpus-per-task OR cpus-per-gpu, the function
89119
# will return a string with the corresponding value

0 commit comments

Comments
 (0)