-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslurm_job.sh
51 lines (38 loc) · 1.96 KB
/
slurm_job.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash -l
#SBATCH --job-name=example_job # Custom job name. i.a. will be displayed in squeue
#SBATCH --ntasks=1 # Define task count
#SBATCH --nodes=1 # Define node count
#SBATCH --cpus-per-task=4 # Define cpu core count per task
#SBATCH --time=0-00:05:00 # Expected run time hard cap, if exceeded will force stop the job [d-hh:mm:ss]
#SBATCH --partition main # Partition for your job e.g. GPU to run on. See options with command sinfo
#SBATCH --qos=standard # Set job priority [standard, prio, hiprio]
# Memory hard cap per node / per cpu, if exceeded will force stop the job
##SBATCH --mem-per-cpu=1500MB # this one is not in effect, due to the double hash
#SBATCH --mem=1GB
# Email event notification [NONE, BEGIN, END, FAIL, ALL]
##SBATCH [email protected] # replace username
##SBATCH --mail-type=END,FAIL
# You may not place any commands before the last SBATCH directive
# Loads most recent Python installed on cluster. See all modules with command module avail
module add Python
# Define a unique scratch directory for the job
SCRATCH_DIRECTORY=/scratch/${USER}/${SLURM_JOB_NAME}/${SLURM_JOBID}
# Define a unique home output directory for the job
OUTPUT_DIRECTORY=/${SLURM_SUBMIT_DIR}/output/$(date +%F)_${SLURM_JOBID}
# Create directories if not exist
mkdir -p "${OUTPUT_DIRECTORY}"
mkdir -p "${SCRATCH_DIRECTORY}/out"
# Copy job script to scratch directory
cp "${SLURM_SUBMIT_DIR}/slurm_job.py" "${SCRATCH_DIRECTORY}"
# Execute script and redirect output to file located in out folder
# Core count is passed to script via argv[1]
cd "${SCRATCH_DIRECTORY}" || exit
echo "now processing ${SLURM_JOB_NAME} - ${SLURM_JOBID}"
python3 slurm_job.py "${SLURM_CPUS_PER_TASK}" > out/"output_${SLURM_JOB_NAME}_${SLURM_JOBID}.txt"
# After script is done, copy all file in out folder to the output directory in home
cp out/* "${OUTPUT_DIRECTORY}"
# Leave scratch directory and delete it
cd "${SLURM_SUBMIT_DIR}" || exit
rm -rf "${SCRATCH_DIRECTORY}"
# finish
exit 0