Submit your first Slurm job

Simple Python job example

1. SSH to SuperPod login node, please check here: How to login

2. Save the below example python code as test.py in your home directory

import numpy as np
import time

# Generate two random arrays
size = 300000
a = np.random.rand(size)
b = np.random.rand(size)

# Method 1: Compute dot product using a loop
dot_product = 0

start = time.time()
for i in range(size):
  dot_product += a[i] * b[i]
end = time.time()

print(f"Dot product using loop: {dot_product}")
print("Time : ",end - start)

# Method 2: Compute dot product using vectorization
start2 = time.time()
dot_product_vec = np.dot(a, b)
end2 = time.time()

print(f"Dot product using vectorization: {dot_product_vec}")
print("Time : ",end2 - start2)

3. If you would like to try your code in login node, type below:

% module load Anaconda3/2023.09-0
% python test.py
Dot product using loop: 74979.16429226683
Time :  0.10371804237365723
Dot product using vectorization: 74979.16429226879
Time :  0.026628971099853516

4, Prepare a sbatch script file, say test.sbatch for job submission, Remember to provide your partition name as appropriate.  If you are not specifying the partition name (the #SBATCH line for partition name), it is default to the normal partition. For different account types, you can access to different partitions and different GPU configuration. Please refer to here and FAQ page for more information. If you belong to multiple project teams, please also specify the project name to be accounted in the sbatch job.

#!/bin/bash
#SBATCH --job-name=test          # create a short name for your job
#SBATCH --nodes=1                # node count
#SBATCH --gpus=1                 # number of GPUs per node(only valid under large/normal partition)
#SBATCH --time=00:20:00          # total run time limit (HH:MM:SS)
#SBATCH --partition=<queuename>  # partition(large/normal/cpu) where you submit
#SBATCH --account=<project>      # only require for multiple projects

module purge                     # clear environment modules inherited from submission
module load Anaconda3/2023.09-0  # load the exact modules required

python test.py

5. Submit your task using "sbatch" command

% sbatch --wait -o slurm.out test.sbatch

6. Check the result and the output should be similar to the above running manually.

% cat slurm.out