|
1 | | -# Main Slurm Commands |
| 1 | +# Main Slurm commands |
2 | 2 |
|
3 | | -## Submit Jobs |
| 3 | +## Submitting jobs |
4 | 4 |
|
5 | 5 | <!--submit-start--> |
6 | 6 |
|
7 | | -There are three ways of submitting jobs with slurm, using either [`sbatch`](https://slurm.schedmd.com/sbatch.html), [`srun`](https://slurm.schedmd.com/srun.html) or [`salloc`](https://slurm.schedmd.com/salloc.html): |
| 7 | +Jobs in the [Slurm scheduler](/slurm/) are executed in batch or interactive mode. Batch jobs are executed asynchronously in the background, whereas interactive jobs allow the user to issue commands directly in a shell session. In both cases, the users must request resources for his job, including a finite amount of time for which they can occupy the compute resources. |
8 | 8 |
|
9 | | -=== "sbatch (passive job)" |
10 | | - ```bash |
11 | | - ### /!\ Adapt <partition>, <qos>, <account> and <command> accordingly |
12 | | - sbatch -p <partition> [--qos <qos>] [-A <account>] [...] <path/to/launcher.sh> |
13 | | - ``` |
14 | | -=== "srun (interactive job)" |
| 9 | +The batch launcher script may contain `srun` commands to launch [job steps](). The job steps can run in sequence or in parallel given that enough resources are available in the job allocation or that resources can be shared. Access to resources such as nodes, memory, and accelerator devices, can be requested with appropriate [partition](/partitions/) and [constraint]() options. |
| 10 | + |
| 11 | +### Executing a job in batch mode with `sbatch` |
| 12 | + |
| 13 | +<!--sbatch-start--> |
| 14 | + |
| 15 | +_Batch job scripts_ are submitted to the scheduler with the [`sbatch`](https://slurm.schedmd.com/sbatch.html) command. |
| 16 | + |
| 17 | +- The command adds a resource allocation request to the scheduler job queue together with a _copy_ of a job luncher script to execute in the allocation. The command then exits. |
| 18 | +- When the requested resources are available, a job is lunched and the job script is executed in the first node of the allocated resources. |
| 19 | +- The job allocation is freed when the job script finishes or the allocation times out. |
| 20 | + |
| 21 | +The execution of the job script is thus asynchronous to the execution of the `sbatch` command. |
| 22 | + |
| 23 | +!!! info "Typical `sbatch` (batch job) options" |
| 24 | + To submit a bash job script to be executed asynchronously by the scheduler use the following `sbatch` command. |
15 | 25 | ```bash |
16 | | - ### /!\ Adapt <partition>, <qos>, <account> and <command> accordingly |
17 | | - srun -p <partition> [--qos <qos>] [-A <account>] [...] ---pty bash |
| 26 | + sbatch --partition=<partition> [--qos=<qos>] [--account=<account>] [...] <path/to/launcher_script.sh> |
18 | 27 | ``` |
19 | | - `srun` is also to be using within your launcher script to initiate a _job step_. |
| 28 | + Upon job submission, Slurm print a message with the job's ID; the job ID is used to identify this job in all Slurm interactions. |
20 | 29 |
|
21 | | -=== "salloc (request allocation/interactive job)" |
22 | | - ```bash |
23 | | - # Request interactive jobs/allocations |
24 | | - ### /!\ Adapt <partition>, <qos>, <account> and <command> accordingly |
25 | | - salloc -p <partition> [--qos <qos>] [-A <account>] [...] <command> |
| 30 | +!!! warning "Accessing script from a submission script" |
| 31 | + If you reference any other script or program from the submission script, the ensure that the file referenced is accessible. |
| 32 | + |
| 33 | + - Use the full path to the file referenced. |
| 34 | + - Ensure that the file is stored in a networked file system and accessible from every node. |
| 35 | + |
| 36 | +!!! example "Example job submission" |
| 37 | + ```console |
| 38 | + $ sbatch <path/to/launcher_script.sh> |
| 39 | + submitted batch job 864933 |
26 | 40 | ``` |
| 41 | +<!--sbatch-end--> |
27 | 42 |
|
28 | | -### `sbatch` |
| 43 | +### Execute a job in interactive mode with `salloc` |
29 | 44 |
|
30 | | -<!--sbatch-start--> |
| 45 | +_Interactive jobs_ are launched with the [`salloc`](https://slurm.schedmd.com/salloc.html) command. |
31 | 46 |
|
32 | | -[`sbatch`](https://slurm.schedmd.com/sbatch.html) is used to submit a batch _launcher script_ for later execution, corresponding to _batch/passive submission mode_. |
33 | | -The script will typically contain one or more `srun` commands to launch parallel tasks. |
34 | | -Upon submission with `sbatch`, Slurm will: |
| 47 | +- The command submits a resources allocation request to the scheduler job queue, and blocks until the resources are available. |
| 48 | +- When the requested resources are available, a job is lunched and a command is executed in the first node of the allocated resources. |
| 49 | +- The allocation is freed when the interactive session terminates with and `exit` command, or the allocation times out. |
35 | 50 |
|
36 | | -* allocate resources (nodes, tasks, partition, constraints, etc.) |
37 | | -* runs a single **copy** of the batch script on the _first_ allocated node |
38 | | - - in particular, if you depend on other scripts, ensure you have refer to them with the _complete_ path toward them. |
| 51 | +The main difference of `salloc` from `sbatch` is that the `salloc` runs for the whole runtime of the command that is executed in the allocation, that it `salloc` is a blocking version of `sbatch`. |
39 | 52 |
|
40 | | -When you submit the job, Slurm responds with the job's ID, which will be used to identify this job in reports from Slurm. |
| 53 | +!!! info "Typical `salloc` (interactive job) options" |
| 54 | + To start an interactive job scheduler use the following `salloc` command. |
| 55 | + ```bash |
| 56 | + sbatch --partition=<partition> [--qos=<qos>] [--account=<account>] [--x11] [...] [<commmand>] |
| 57 | + ``` |
| 58 | + - The `salloc` command will block until the requested resources are available, and it will the launch the `<command>` in the first node of the allocation. |
| 59 | + - The `<command>` argument is optional; if no command is provided then the behavior of `salloc` depends on the configuration of Slurm. Our site Slurm is configured to launch an interactive shell when no `<command>` is provided. |
| 60 | + Upon job submission, Slurm print a message with the job's ID; the job ID is used to identify this job in all Slurm interactions. |
41 | 61 |
|
42 | | -```bash |
43 | | -# /!\ ADAPT path to launcher accordingly |
44 | | -$ sbatch <path/to/launcher>.sh |
45 | | -Submitted batch job 864933 |
46 | | -``` |
47 | | -<!--sbatch-end--> |
| 62 | +!!! example "Example interactive job submission" |
| 63 | + ```console |
| 64 | + $ salloc --partition=batch --qos=normal --nodes=1 --time=8:00:00 |
| 65 | + salloc: Granted job allocation 9805184 |
| 66 | + salloc: Nodes aion-0207 are ready for job |
| 67 | + ``` |
48 | 68 |
|
49 | | -### `srun` |
| 69 | +??? info "Configuring the default behavior of `salloc`" |
50 | 70 |
|
51 | | -[`srun`](https://slurm.schedmd.com/srun.html) is used to initiate parallel _job steps within a job_ **OR** to _start an interactive job_ |
52 | | -Upon submission with `srun`, Slurm will: |
| 71 | + The [LaunchParameters](https://slurm.schedmd.com/slurm.conf.html#OPT_LaunchParameters) option of Slurm configuration ([`slurm.conf`](https://slurm.schedmd.com/slurm.conf.html)) is a comma separated list of options for the job launch plugin. The `use_interactive_step` option has `salloc` launch a shell on the first node of the allocation; otherwise `salloc` launches a shell locally, in the machine where it was invoked. |
53 | 72 |
|
54 | | -* (_eventually_) allocate resources (nodes, tasks, partition, constraints, etc.) when run for _interactive_ submission |
55 | | -* launch a job step that will execute on the allocated resources. |
| 73 | + The [InteractiveStepOptions](https://slurm.schedmd.com/slurm.conf.html#OPT_InteractiveStepOptions) of Slurm configuration determines the command run by `salloc` when `use_interactive_step` is included in LaunchParameters. The default value is |
| 74 | + ``` |
| 75 | + --interactive --preserve-env --pty $SHELL" |
| 76 | + ``` |
| 77 | + where `--interactive` creates an "interactive step" that will not consume resources so that other job steps may run in parallel with the interactive step running the shell. The [`--pty` option](https://slurm.schedmd.com/srun.html#OPT_pty) is required when creating an implicit reservation for an interactive shell. |
56 | 78 |
|
57 | | -A job can contain multiple job steps executing sequentially |
58 | | -or in parallel on independent or shared resources within the job's |
59 | | -node allocation. |
| 79 | + Note that `--interactive` is an internal potion and is not meant to be used outside setting the InteractiveStepOptions. |
60 | 80 |
|
61 | | -### salloc |
| 81 | +To create a allocation without launching any command, use the `--no-shell` option. Then `salloc` immediately exits after allocating job resources without running a command. Job steps can still be launched in the job allocation using the `srun` command with the `--jobid=<job allocation id>` command. |
62 | 82 |
|
63 | | -[`salloc`](https://slurm.schedmd.com/salloc.html) is used to _allocate_ resources for a job |
64 | | -in real time. Typically this is used to allocate resources (nodes, tasks, partition, etc.) and spawn a |
65 | | -shell. The shell is then used to execute srun commands to launch |
66 | | -parallel tasks. |
| 83 | +### Implicit job creation with `srun` |
| 84 | + |
| 85 | +The [`srun`](https://slurm.schedmd.com/srun.html) is used to initiate parallel job steps within a job allocation. However, if `srun` is invoked outside an allocation, then |
| 86 | + |
| 87 | +- `srun` automatically allocates a job in a blocking manner similar to `salloc`, and |
| 88 | +- when the requested resources become available, it launches a single job step to run the provided command. |
| 89 | + |
| 90 | +??? info "Lunching job with `srun`" |
| 91 | + To create an implicit job allocation and launch a job step with `srun` provide the usual options usually required by `salloc` or `sbatch`. |
| 92 | + ```bash |
| 93 | + srun --partition=<partition> [--qos=<qos>] [--account=<account>] [...] <command> |
| 94 | + ``` |
| 95 | + To launch an interactive allocation, use the [`--pty` option](https://slurm.schedmd.com/srun.html#OPT_pty). |
| 96 | + ```bash |
| 97 | + srun --partition=<partition> [--qos=<qos>] [--account=<account>] [...] --pty bash --login |
| 98 | + ``` |
| 99 | + The `--pty` option instructs `srun` to execute the command in [terminal mode](https://en.wikipedia.org/wiki/Terminal_mode) in a [pseudoterminal](https://en.wikipedia.org/wiki/Pseudoterminal), so you can interact with bash as if it was launched in your terminal. |
67 | 100 |
|
68 | 101 | <!--submit-end--> |
69 | 102 |
|
|
0 commit comments