Skip to content

Commit f8a0bfc

Browse files
fix: cgroup confinement (#23)
fix #41 --------- Co-authored-by: meesters <meesters@uni-mainz.de> Co-authored-by: Christian Meesters <cmeesters@users.noreply.github.com>
1 parent 5bd656c commit f8a0bfc

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

snakemake_executor_plugin_slurm_jobstep/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
JobExecutorInterface,
1414
)
1515
from snakemake_interface_executor_plugins.settings import ExecMode, CommonSettings
16+
from snakemake_interface_common.exceptions import WorkflowError
1617

1718

1819
# Required:
@@ -111,7 +112,15 @@ def run_job(self, job: JobExecutorInterface):
111112
# The -n1 is important to avoid that srun executes the given command
112113
# multiple times, depending on the relation between
113114
# cpus per task and the number of CPU cores.
114-
call = f"srun -n1 --cpu-bind=q {self.format_job_exec(job)}"
115+
116+
# as of v22.11.0, the --cpu-per-task flag is needed to ensure that
117+
# the job can utilize the c-group's resources.
118+
# We set the limitation accordingly, assuming the submit executor
119+
# has set the resources correctly.
120+
121+
call = "srun -n1 --cpu-bind=q "
122+
call += f"--cpus-per-task {get_cpus_per_task(job)} "
123+
call += f"{self.format_job_exec(job)}"
115124

116125
self.logger.debug(f"This job is a group job: {job.is_group()}")
117126
self.logger.debug(f"The call for this job is: {call}")
@@ -144,3 +153,16 @@ def cores(self):
144153

145154
def get_exec_mode(self) -> ExecMode:
146155
return ExecMode.REMOTE
156+
157+
158+
def get_cpus_per_task(job: JobExecutorInterface):
159+
cpus_per_task = job.threads
160+
if job.resources.get("cpus_per_task"):
161+
if not isinstance(cpus_per_task, int):
162+
raise WorkflowError(
163+
f"cpus_per_task must be an integer, but is {cpus_per_task}"
164+
)
165+
cpus_per_task = job.resources.cpus_per_task
166+
# ensure that at least 1 cpu is requested
167+
# because 0 is not allowed by slurm
168+
return max(1, cpus_per_task)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rule all:
2+
input: "1.out"
3+
4+
rule test1:
5+
output: "1.out"
6+
#threads: 2
7+
resources:
8+
cpus_per_task=1
9+
shell: "touch $SLURM_CPUS_PER_TASK.out"
10+

tests/test_github_issue41/expected_results/1.out

Whitespace-only changes.

tests/tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ def get_executor(self) -> str:
1212
def get_executor_settings(self) -> Optional[ExecutorSettingsBase]:
1313
# instatiate ExecutorSettings of this plugin as appropriate
1414
return None
15+
16+
17+
# def test_issue_41():
18+
# run(dpath("test_github_issue41"))

0 commit comments

Comments
 (0)