You are located in service: RWTH High Performance Computing (Linux)

Example Batch Scripts

Example Batch Scripts

Detailinformation

Serial

A sample program ./a.out that does not use MPI:

#!/usr/bin/zsh

### Ask for 10 GB memory
#SBATCH --mem-per-cpu=10240M   #M is the default and can therefore be omitted, but could also be K(ilo)|G(iga)|T(era)

### Name the job
#SBATCH --job-name=SERIAL_JOB

### Declare the merged STDOUT/STDERR file
#SBATCH --output=output.%J.txt

### Begin of executable commands
./a.out

OpenMP

A sample program ./a.out that only uses OpenMP multithreading:

#!/usr/bin/zsh

### Ask for eight cores
#SBATCH --cpus-per-task=8

#################
# ATTENTION !!! #
#################
#
# Divide the needed memory per task through the cpus-per-task, as slurm requests memory per cpu, not per task!
# Example:
# You need 2 GB memory per task, you have 8 cpus per task ordered
# order 2048/8 -> 256M memory
#SBATCH --mem-per-cpu=256M

### Name the job
#SBATCH --job-name=OPENMP_JOB

### Declare the merged STDOUT/STDERR file
#SBATCH --output=output.%J.txt

### Beginning of executable commands
# Note: the OMP_NUM_THREADS envvar is set automatically - do not overwrite!

./a.out

MPI

A sample program ./a.out that uses MPI parallelism:

#!/usr/bin/zsh

### Ask for eight tasks (MPI Ranks)
#SBATCH --ntasks=8

### Ask for one node, use several nodes in case you need additional resources
#SBATCH --nodes=1

### Ask for less than 4 GB memory per task=MPI rank
#SBATCH --mem-per-cpu=3900M   #M is the default and can therefore be omitted, but could also be K(ilo)|G(iga)|T(era)

### Name the job
#SBATCH --job-name=MPI_JOB

### Declare the merged STDOUT/STDERR file
#SBATCH --output=output.%J.txt

### Beginning of executable commands
$MPIEXEC $FLAGS_MPI_BATCH ./a.out

Hybrid

This example illustrates a batch script for an MPI + OpenMP hybrid job, which uses 2 CLAIX 18 nodes with 4 ranks, 2 ranks per node, 1 MPI rank per socket and 24 OMP threads per socket. This uses all 48 cores per node.

#!/usr/bin/zsh

### Ask for four tasks (which are 4 MPI ranks)
#SBATCH --ntasks=4

### Ask for 24 threads per task=MPI rank (which is 1 thread per core on one socket on CLAIX18)
#SBATCH --cpus-per-task=24

#################
# ATTENTION !!! #
#################
# Divide the needed memory per task through the cpus-per-task, as slurm requests memory per cpu, not per task !
# Example:
# You need 24 GB memory per task, you have 24 cpus per task ordered
# order 24GB/24 -> 1G memory per cpu (i.e., per thread)
#SBATCH --mem-per-cpu=1G

### Name the job
#SBATCH --job-name=HYBRID_JOB

### Declare the merged STDOUT/STDERR file
#SBATCH --output=output.%J.txt

### Beginning of executable commands
### Note: the OMP_NUM_THREADS envvar is set automatically - do not overwrite!

$MPIEXEC $FLAGS_MPI_BATCH ./a.out

Simple GPU Example

Please Note: Loading a CUDA module may require loading additional modules. Check the output of module spider CUDA/<version> for information.

Run deviceQuery (from NVIDIA SDK) on one device:

#!/usr/bin/zsh

#SBATCH -J gpu_serial
#SBATCH -o gpu_serial.%J.log
#SBATCH --gres=gpu:1

module load CUDA

# Print some debug information
echo; export; echo; nvidia-smi; echo

$CUDA_ROOT/extras/demo_suite/deviceQuery -noprompt

MPI + GPU

To run an MPI application on the GPU nodes, you need to take special care to correctly set the numer of MPI ranks per node. Typical setups are:

  1. One process per node (ppn):

    If your process uses both GPUs at the same time, e.g. via cudaSetDevice or by accepting CUDA_VISIBLE_DEVICES (set automatically by the batch system). Let ./cuda-mpi be the path to your MPI-compatible CUDA program:

    #!/usr/bin/zsh
    
    ### Setup in this script:
    ### - 4 nodes (c18g)
    ### - 1 rank per node
    ### - 2 GPUs per rank (= both GPUs from the node)
    #SBATCH -J 4-1-2
    #SBATCH -o 4-1-2.%J.log
    #SBATCH --ntasks=4
    #SBATCH --ntasks-per-node=1
    #SBATCH --gres=gpu:2
    
    module load CUDA
    
    # Print some debug information
    echo; export; echo; nvidia-smi; echo
    
    $MPIEXEC $FLAGS_MPI_BATCH ./cuda-mpi
    
  2. two processes per node (ppn):

    If each process communicates to its own single GPU and thus using both GPUs on a node (recommended setup). Let ./cuda-mpi be the path to your MPI-compatible CUDA program:

    #!/usr/bin/zsh
    
    ### Setup in this script:
    ### - 2 nodes (c18g, default)
    ### - 2 ranks per node
    ### - 1 GPU per rank (= both GPUs from the node)
    
    #SBATCH -J 2-2-1
    #SBATCH -o 2-2-1.%J.log
    #SBATCH --ntasks=4
    #SBATCH --ntasks-per-node=2
    #SBATCH --gres=gpu:2
    
    module load CUDA
    
    #print some debug informations...
    echo; export; echo; nvidia-smi; echo
    
    $MPIEXEC $FLAGS_MPI_BATCH ./cuda-mpi
    
  3. More than 2 processes per node:

    If you also have processes that do computation on the CPU only.


 Zusatzinformation

Hybrid toy example for download

Please find a hybrid Fortran toy code, Makefile and Slurm job script for download here. You need to adjust your project account, your working directory and probably your job log file name in slurm.job.

Download

hybrid-slurm-example.tar

extract using the command

tar -xf hybrid-slurm-example.tar

edit and adjust the file slurm.job

Compile with: make compile

and submit with: make submit

and check the job log file after the job has terminated.

last changed on 03/27/2023

How did this content help you?

Creative Commons Lizenzvertrag
This work is licensed under a Creative Commons Attribution - Share Alike 3.0 Germany License