Skip to content

Commit c9605a9

Browse files
add docs
1 parent f79b681 commit c9605a9

File tree

1 file changed

+143
-2
lines changed

1 file changed

+143
-2
lines changed

README.md

+143-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,144 @@
1-
# snakemake-executor-plugin-slurm
1+
# Snakemake executor plugin: slurm
22

3-
A Snakemake executor plugin for submitting jobs to a SLURM cluster.
3+
[SLURM](https://slurm.schedmd.com/documentation.html) is a widely used
4+
batch system for performance compute clusters.
5+
6+
## Specifying Account and Partition
7+
8+
Most SLURM clusters have two mandatory resource indicators for
9+
accounting and scheduling, [Account]{.title-ref} and
10+
[Partition]{.title-ref}, respectivily. These resources are usually
11+
omitted from Snakemake workflows in order to keep the workflow
12+
definition independent from the platform. However, it is also possible
13+
to specify them inside of the workflow as resources in the rule
14+
definition (see `snakefiles-resources`{.interpreted-text role="ref"}).
15+
16+
To specify them at the command line, define them as default resources:
17+
18+
``` console
19+
$ snakemake --executor slurm --default-resources slurm_account=<your SLURM account> slurm_partition=<your SLURM partition>
20+
```
21+
22+
If individual rules require e.g. a different partition, you can override
23+
the default per rule:
24+
25+
``` console
26+
$ snakemake --slurm --default-resources slurm_account=<your SLURM account> slurm_partition=<your SLURM partition> --set-resources <somerule>:slurm_partition=<some other partition>
27+
```
28+
29+
Usually, it is advisable to persist such settings via a
30+
[configuration profile](https://snakemake.readthedocs.io/en/latest/executing/cli.html#profiles), which
31+
can be provided system-wide, per user, and in addition per workflow.
32+
33+
## Ordinary SMP jobs
34+
35+
Most jobs will be carried out by programs which are either single core
36+
scripts or threaded programs, hence SMP ([shared memory
37+
programs](https://en.wikipedia.org/wiki/Shared_memory)) in nature. Any
38+
given threads and `mem_mb` requirements will be passed to SLURM:
39+
40+
``` python
41+
rule a:
42+
input: ...
43+
output: ...
44+
threads: 8
45+
resources:
46+
mem_mb=14000
47+
```
48+
49+
This will give jobs from this rule 14GB of memory and 8 CPU cores. It is
50+
advisable to use resonable default resources, such that you don\'t need
51+
to specify them for every rule. Snakemake already has reasonable
52+
defaults built in, which are automatically activated when using any non-local executor
53+
(hence also with slurm).
54+
55+
## MPI jobs {#cluster-slurm-mpi}
56+
57+
Snakemake\'s Slurm backend also supports MPI jobs, see
58+
`snakefiles-mpi`{.interpreted-text role="ref"} for details. When using
59+
MPI with slurm, it is advisable to use `srun` as MPI starter.
60+
61+
``` python
62+
rule calc_pi:
63+
output:
64+
"pi.calc",
65+
log:
66+
"logs/calc_pi.log",
67+
resources:
68+
tasks=10,
69+
mpi="srun",
70+
shell:
71+
"{resources.mpi} -n {resources.tasks} calc-pi-mpi > {output} 2> {log}"
72+
```
73+
74+
Note that the `-n {resources.tasks}` is not necessary in case of SLURM,
75+
but it should be kept in order to allow execution of the workflow on
76+
other systems, e.g. by replacing `srun` with `mpiexec`:
77+
78+
``` console
79+
$ snakemake --set-resources calc_pi:mpi="mpiexec" ...
80+
```
81+
82+
## Advanced Resource Specifications
83+
84+
A workflow rule may support a number of
85+
[resource specifications](https://snakemake.readthedocs.io/en/latest/snakefiles/rules.html#resources).
86+
For a SLURM cluster, a mapping between Snakemake and SLURM needs to be performed.
87+
88+
You can use the following specifications:
89+
90+
| SLURM | Snakemake | Description |
91+
|----------------|------------|---------------------------------------|
92+
| `--partition` | `slurm_partition` | the partition a rule/job is to use |
93+
| `--time` | `runtime` | the walltime per job in minutes |
94+
| `--constraint` | `constraint` | may hold features on some clusters |
95+
| `--mem` | `mem`, `mem_mb` | memory a cluster node must |
96+
| | | provide (`mem`: string with unit), `mem_mb`: i |
97+
| `--mem-per-cpu` | `mem_mb_per_cpu` | memory per reserved CPU |
98+
| `--ntasks` | `tasks` | number of concurrent tasks / ranks |
99+
| `--cpus-per-task` | `cpus_per_task` | number of cpus per task (in case of SMP, rather use `threads`) |
100+
| `--nodes` | `nodes` | number of nodes |
101+
102+
Each of these can be part of a rule, e.g.:
103+
104+
``` python
105+
rule:
106+
input: ...
107+
output: ...
108+
resources:
109+
partition: <partition name>
110+
runtime: <some number>
111+
```
112+
113+
Please note: as `--mem` and `--mem-per-cpu` are mutually exclusive on
114+
SLURM clusters, their corresponding resource flags `mem`/`mem_mb` and
115+
`mem_mb_per_cpu` are mutually exclusive, too. You can only reserve
116+
memory a compute node has to provide or the memory required per CPU
117+
(SLURM does not make any distintion between real CPU cores and those
118+
provided by hyperthreads). SLURM will try to sastify a combination of
119+
`mem_mb_per_cpu` and `cpus_per_task` and `nodes`, if `nodes` is not
120+
given.
121+
122+
Note that it is usually advisable to avoid specifying SLURM (and compute
123+
infrastructure) specific resources (like `constraint`) inside of your
124+
workflow because that can limit the reproducibility on other systems.
125+
Consider using the `--default-resources` and `--set-resources` flags to specify such resources
126+
at the command line or (ideally) within a [profile](https://snakemake.readthedocs.io/en/latest/executing/cli.html#profiles).
127+
128+
## Additional custom job configuration
129+
130+
SLURM installations can support custom plugins, which may add support
131+
for additional flags to `sbatch`. In addition, there are various
132+
`sbatch` options not directly supported via the resource definitions
133+
shown above. You may use the `slurm_extra` resource to specify
134+
additional flags to `sbatch`:
135+
136+
``` python
137+
rule myrule:
138+
input: ...
139+
output: ...
140+
resources:
141+
slurm_extra="--qos=long --mail-type=ALL --mail-user=<your email>"
142+
```
143+
144+
Again, rather use a [profile](https://snakemake.readthedocs.io/en/latest/executing/cli.html#profiles) to specify such resources.

0 commit comments

Comments
 (0)