| Both sides previous revision Previous revision Next revision | Previous revision |
| tutorials_scheduler [2025/05/23 18:17] – [Non-interactive Jobs] docuadmin | tutorials_scheduler [2025/05/27 19:32] (current) – [Non-interactive Jobs] docuadmin |
|---|
| |
| ===== Non-interactive Jobs ===== | ===== Non-interactive Jobs ===== |
| | |
| | **Non-interactive jobs** are submitted to the scheduler using one of two commands: ''srun'' and ''sbatch''. |
| | The ''srun'' command submits a job for execution in real time. If ''srun'' is invoked within an allocation acquired through ''salloc'' then the ''srun'' command uses that allocation to execute the job immediately. If ''srun'' is invoked without a previously acquired allocation, the job parameters issued with the ''srun'' command are used to request an allocation and execute the job. |
| | |
| | This ''srun'' command will execute the ''hostname'' command with the default allocation of 1 node and 1 task: |
| | |
| | srun hostname |
| | |
| | The result is the hostname of the compute node on which the ''hostname'' command is executed. This ''srun'' command will execute the ''hostname'' command 10 times, 5 times on each of 2 requested nodes: |
| | |
| | srun -N 2 -n 10 hostname |
| | |
| | The result is the hostname of each of the compute nodes will be printed 5 times. |
| | |
| | The ''sbatch'' command submits a batch script to be executed at a time of the scheduler's choosing: presumably as soon as all the requested resources become available. A batch script contains SLURM directives (specifying required resources and job properties) and commands to be executed as part of the job. |
| | |
| | A batch script submitted to ''sbatch'' will contain SLURM directives at the start of the script. These directives mirror the options and parameters that can be passed to ''srun'' as flags to specify the number of nodes, tasks, and other SLURM-related options of the job. These directives are placed in the batch script, one per line, with the line beginning with "#SBATCH". These options set up the execution environment for the commands that follow later in the script. |
| | |
| | #!/bin/bash |
| | |
| | #SBATCH -N 2 |
| | #SBATCH -n 10 |
| | ... |
| | |
| | Following the ''#SBATCH'' directives will be the commands or scripts that make up the compute job you want to execute. To distribute the tasks across the allocated processors, the batch script should contain an 'srun' command or similar command (''mpirun'', ''mpiexec'', etc) to assign tasks to allocated processors. Without such a command the commands issued in the batch script will just be steps in a single task assigned to a single processor. The output of the following batch script will illustrate this: |
| | |
| | File ''printhostname.sub'': |
| | |
| | #!/bin/bash |
| | |
| | #SBATCH -N 2 |
| | #SBATCH -n 10 |
| | |
| | echo "This command is executed on $('hostname') |
| | echo "The following 'hostname' commands come from 'srun':" |
| | srun hostname | sort |
| | |
| | Submit a batch job by supplying the batch script as the first argument of the 'sbatch' command: |
| | |
| | sbatch printhostname.sub |
| | |
| | Output: |
| | |
| | This command is executed on node1 |
| | The following 'hostname' commands come from 'srun': |
| | node1 |
| | node1 |
| | node1 |
| | node1 |
| | node1 |
| | node2 |
| | node2 |
| | node2 |
| | node2 |
| | node2 |
| |
| |