Difference between revisions of "SLURM"

From HPC Wiki
Jump to: navigation, search
Line 222: Line 222:
 
srun myapp.exe
 
srun myapp.exe
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
You can use this hybrid toy Fortran90 program to test the above job script
 +
<syntaxhighlight lang="bash">
 +
program hello
 +
  use mpi
 +
  use omp_lib
 +
 +
  integer rank, size, ierror, tag, status(MPI_STATUS_SIZE),threadid
 +
  character*(MPI_MAX_PROCESSOR_NAME) name
 +
 
 +
  call MPI_INIT(ierror)
 +
  call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
 +
  call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror)
 +
  call MPI_GET_PROCESSOR_NAME(name,len,ierror)
 +
 
 +
!$omp parallel private(threadid)
 +
  threadid=omp_get_thread_num()
 +
  print*, 'node: ', trim(name), '  rank:', rank, ', thread_id:', threadid
 +
!$omp end parallel
 +
 
 +
  call MPI_FINALIZE(ierror)
 +
 
 +
end program
 +
</syntaxhighlight>
 +
 +
When sorting the program output it may look like
 +
<syntaxhighlight lang="fortran">
 +
node: ncm1018.hpc.itc.rwth-aachen.de  rank:          0 , thread_id:          0
 +
node: ncm1018.hpc.itc.rwth-aachen.de  rank:          0 , thread_id:          1
 +
node: ncm1018.hpc.itc.rwth-aachen.de  rank:          0 , thread_id:          2
 +
node: ncm1018.hpc.itc.rwth-aachen.de  rank:          1 , thread_id:          0
 +
node: ncm1018.hpc.itc.rwth-aachen.de  rank:          1 , thread_id:          1
 +
node: ncm1018.hpc.itc.rwth-aachen.de  rank:          1 , thread_id:          2
 +
node: ncm1019.hpc.itc.rwth-aachen.de  rank:          2 , thread_id:          0
 +
node: ncm1019.hpc.itc.rwth-aachen.de  rank:          2 , thread_id:          1
 +
node: ncm1019.hpc.itc.rwth-aachen.de  rank:          2 , thread_id:          2
 +
node: ncm1019.hpc.itc.rwth-aachen.de  rank:          3 , thread_id:          0
 +
node: ncm1019.hpc.itc.rwth-aachen.de  rank:          3 , thread_id:          1
 +
node: ncm1019.hpc.itc.rwth-aachen.de  rank:          3 , thread_id:          2
 +
</syntaxhighlight>
 +
 
== Site specific notes ==
 
== Site specific notes ==
  

Revision as of 18:50, 20 December 2018

General

SLURM is a workload manager / job scheduler. To get an overview of the functionality of a scheduler, go here or to the Scheduling Basics.



#SBATCH Usage

If you are writing a jobscript for a SLURM batch system, the magic cookie is "#SBATCH". To use it, start a new line in your script with "#SBATCH". Following that, you can put one of the parameters shown below, where the word written in <...> should be replaced with a value.

Basic settings:

Parameter Function
--job-name=<name> job name
--output=<path> path to the file where the job (error) output is written to

Requesting resources:

Parameter Function
--time=<runlimit> runtime limit in the format hours:min:sec; once the time specified is up, the job will be killed by the scheduler
--mem=<memlimit> job memory request per node, usually an integer followed by a prefix for the unit (e. g. --mem=1G for 1 GB)

Parallel programming (read more here):

Settings for OpenMP:

Parameter Function
--nodes=1 start a parallel job for a shared-memory system on only one node
--cpus-per-task=<num_threads> number of threads to execute OpenMP application with
--ntasks-per-core=<num_hyperthreads> number of hyperthreads per core; i. e. any value greater than 1 will turn on hyperthreading (the possible maximum depends on your CPU)
--ntasks-per-node=1 for OpenMP, use one task per node only

Settings for MPI:

Parameter Function
--nodes=<num_nodes> start a parallel job for a distributed-memory system on several nodes
--cpus-per-task=1 for MPI, use one task per CPU
--ntasks-per-core=1 disable hyperthreading
--ntasks-per-node=<num_procs> number of processes per node (the possible maximum depends on your nodes)

Email notifications:

Parameter Function
--mail-type=<type> type can be one of BEGIN, END, FAIL, REQUEUE or ALL (where a mail will be sent each time the status of your process changes)
--mail-user=<email_address> email address to send notifications to

Job Submission

This command submits the job you defined in your jobscript to the batch system:

$ sbatch jobscript.sh

Just like any other incoming job, your job will first be queued. Then, the scheduler decides when your job will be run. The more resources your job requires, the longer it may be waiting to execute.

You can check the current status of your submitted jobs and their job ids with the following shell command. A job can either be pending PD (waiting for free nodes to run on) or running R (the jobscript is currently being executed). This command will also print the time (hours:min:sec) that your job has been running for.

$ squeue -u <user_id>

In case you submitted a job on accident or realised that your job might not be running correctly, you can always remove it from the queue or terminate it when running by typing:

$ scancel <job_id>

Furthermore, Information about current and past jobs can be accessed via:

$ sacct

with more detailed information at the Slurm documentation of this command

Jobscript Examples

This serial job will run a given executable, in this case "myapp.exe".

#!/bin/bash

### Job name
#SBATCH --job-name=MYJOB

### File for the output
#SBATCH --output=MYJOB_OUTPUT

### Time your job needs to execute, e. g. 15 min 30 sec
#SBATCH --time=00:15:30

### Memory your job needs per node, e. g. 1 GB
#SBATCH --mem=1G

### The last part consists of regular shell commands:
### Change to working directory
cd /home/usr/workingdirectory

### Execute your application
myapp.exe

If you'd like to run a parallel job on a cluster that is managed by SLURM, you have to clarify that. Therefore, use the command "srun <my_executable>" in your jobscript.

This OpenMP job will start the parallel program "myapp.exe" with 24 threads.

#!/bin/bash

### Job name
#SBATCH --job-name=OMPJOB

### File for the output
#SBATCH --output=OMPJOB_OUTPUT

### Time your job needs to execute, e. g. 30 min
#SBATCH --time=00:30:00

### Memory your job needs per node, e. g. 500 MB
#SBATCH --mem=500M

### Use one node for parallel jobs on shared-memory systems
#SBATCH --nodes=1

### Number of threads to use, e. g. 24
#SBATCH --cpus-per-task=24

### Number of hyperthreads per core
#SBATCH --ntasks-per-core=1

### Tasks per node (for shared-memory parallelisation, use 1)
#SBATCH --ntasks-per-node=1

### The last part consists of regular shell commands:
### Set the number of threads in your cluster environment to the value specified above
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

### Change to working directory
cd /home/usr/workingdirectory

### Run your parallel application
srun myapp.exe

This MPI job will start the parallel program "myapp.exe" with 12 processes.

#!/bin/bash

### Job name
#SBATCH --job-name=MPIJOB

### File for the output
#SBATCH --output=MPIJOB_OUTPUT

### Time your job needs to execute, e. g. 50 min
#SBATCH --time=00:50:00

### Memory your job needs per node, e. g. 250 MB
#SBATCH --mem=250M

### Use more than one node for parallel jobs on distributed-memory systems, e. g. 2
#SBATCH --nodes=2

### Number of CPUS per task (for distributed-memory parallelisation, use 1)
#SBATCH --cpus-per-task=1

### Disable hyperthreading by setting the tasks per core to 1
#SBATCH --ntasks-per-core=1

### Number of processes per node, e. g. 6 (6 processes on 2 nodes = 12 processes in total)
#SBATCH --ntasks-per-node=6

### The last part consists of regular shell commands:
### Set the number of threads in your cluster environment to 1, as specified above
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

### Change to working directory
cd /home/usr/workingdirectory

### Run your parallel application
srun myapp.exe


This hybrid MPI+OpenMP job will start the parallel program "myapp.exe" with 4 MPI processes and 3 OpenMP threads each on 2 compute nodes.

#!/bin/zsh

### Job name
#SBATCH --job-name=HelloHybrid

### 2 compute nodes
#SBATCH --nodes=2

### 4 MPI ranks
#SBATCH --ntasks=4

### 2 MPI ranks per node
#SBATCH --ntasks-per-node=2

### 3 tasks per MPI rank
#SBATCH --cpus-per-task=3

### the number of OpenMP threads 
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

### Change to working directory
cd /home/usr/workingdirectory

### Run your parallel application
srun myapp.exe

You can use this hybrid toy Fortran90 program to test the above job script

program hello
   use mpi
   use omp_lib

   integer rank, size, ierror, tag, status(MPI_STATUS_SIZE),threadid
   character*(MPI_MAX_PROCESSOR_NAME) name
   
   call MPI_INIT(ierror)
   call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
   call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror)
   call MPI_GET_PROCESSOR_NAME(name,len,ierror)
   
!$omp parallel private(threadid)
   threadid=omp_get_thread_num()
   print*, 'node: ', trim(name), '  rank:', rank, ', thread_id:', threadid
!$omp end parallel
   
   call MPI_FINALIZE(ierror)
   
end program

When sorting the program output it may look like

 node: ncm1018.hpc.itc.rwth-aachen.de  rank:           0 , thread_id:           0
 node: ncm1018.hpc.itc.rwth-aachen.de  rank:           0 , thread_id:           1
 node: ncm1018.hpc.itc.rwth-aachen.de  rank:           0 , thread_id:           2
 node: ncm1018.hpc.itc.rwth-aachen.de  rank:           1 , thread_id:           0
 node: ncm1018.hpc.itc.rwth-aachen.de  rank:           1 , thread_id:           1
 node: ncm1018.hpc.itc.rwth-aachen.de  rank:           1 , thread_id:           2
 node: ncm1019.hpc.itc.rwth-aachen.de  rank:           2 , thread_id:           0
 node: ncm1019.hpc.itc.rwth-aachen.de  rank:           2 , thread_id:           1
 node: ncm1019.hpc.itc.rwth-aachen.de  rank:           2 , thread_id:           2
 node: ncm1019.hpc.itc.rwth-aachen.de  rank:           3 , thread_id:           0
 node: ncm1019.hpc.itc.rwth-aachen.de  rank:           3 , thread_id:           1
 node: ncm1019.hpc.itc.rwth-aachen.de  rank:           3 , thread_id:           2

Site specific notes

RRZE

  • --output= should not be used on RRZE's clusters; the submit filter already sets suitable defaults automatically
  • --mem=<memlimit> must not be used on RRZE's clusters
  • the first line of the job script should be #/bin/bash -l otherwise module commands won't work in te job script
  • to have a clean environment in job scripts, it is recommended to add #SBATCH --export=NONE and unset SLURM_EXPORT_ENV to the job script. Otherwise, the job will inherit some settings from the submitting shell.
  • access to the parallel file system has to be specified by #SBATCH ---constraint=parfs or the command line shortcut -C parfs
  • access to hardware performance counters (e.g. to be able to use likwid-perfctr) has to be requested by #SBATCH ---constraint=hwperf or the command line shortcut -C hwperf. Only request that feature if you really want to access the ardware performance counters as the feature interferes with the automatic system monitoring.
  • multiple features have to be requested in a single --constraint= statement, listing all required features separated by ampersand, e.g. hwperf&parfs
  • for Intel MPI, RRZE recommends the usage of mpirun instead of srun; if srun shall be used, the additional command line argument --mpi=pmi2 is required. The command line option -ppn of mpirun only works if you export I_MPI_JOB_RESPECT_PROCESS_PLACEMENT=off before.
  • for squeue the option -u user does not have any effect as you always only see your own jobs

References

Advanced SLURM jobscript examples

Detailled guide to more advanced scripts

SBATCH documentation

SLURM jobscript generator