SLURM/ArrayJobs: Difference between revisions

From UMIACS
Jump to navigation Jump to search
(Created page with "<pre> #!/bin/bash ##################### # job-array example # ##################### #SBATCH --job-name=example # 16 jobs will run in this array at the same time #SBATCH --a...")
 
No edit summary
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
Here is an example to get you started using array jobs in [[SLURM]].
==Array computation example job==
Save this code to a file called <code>test.py</code>.
<pre>
import time
print('start at ' + time.strftime('%H:%M:%S'))
print('sleep for 10 seconds ...')
time.sleep(10)
print('stop at ' + time.strftime('%H:%M:%S'))
</pre>
==Sbatch submission script==
Save this to a file called <code>array.sh</code> and you should be able to submit the job as <code>sbatch array.sh</code>.
<pre>
<pre>
#!/bin/bash
#!/bin/bash
Line 15: Line 33:
#SBATCH --time=0-00:05:00
#SBATCH --time=0-00:05:00


# short partition should do it
# default qos should do it
#SBATCH --partition short
#SBATCH --qos=dpart


# 500MB memory per core
# 500MB memory per core
Line 25: Line 43:


# define and create a unique scratch directory
# define and create a unique scratch directory
SCRATCH_DIRECTORY=/global/work/${USER}/job-array-example/${SLURM_JOBID}
SCRATCH_DIRECTORY=/scratch0/${USER}/job-array-example/${SLURM_JOBID}
mkdir -p ${SCRATCH_DIRECTORY}
mkdir -p ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}

Revision as of 19:37, 15 December 2020

Here is an example to get you started using array jobs in SLURM.

Array computation example job

Save this code to a file called test.py.

import time

print('start at ' + time.strftime('%H:%M:%S'))

print('sleep for 10 seconds ...')
time.sleep(10)

print('stop at ' + time.strftime('%H:%M:%S'))

Sbatch submission script

Save this to a file called array.sh and you should be able to submit the job as sbatch array.sh.

#!/bin/bash

#####################
# job-array example #
#####################

#SBATCH --job-name=example

# 16 jobs will run in this array at the same time
#SBATCH --array=1-16

# run for five minutes
#              d-hh:mm:ss
#SBATCH --time=0-00:05:00

# default qos should do it
#SBATCH --qos=dpart

# 500MB memory per core
# this is a hard limit 
#SBATCH --mem-per-cpu=500MB

# you may not place bash commands before the last SBATCH directive

# define and create a unique scratch directory
SCRATCH_DIRECTORY=/scratch0/${USER}/job-array-example/${SLURM_JOBID}
mkdir -p ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}

cp ${SLURM_SUBMIT_DIR}/test.py ${SCRATCH_DIRECTORY}

# each job will see a different ${SLURM_ARRAY_TASK_ID}
echo "now processing task id:: " ${SLURM_ARRAY_TASK_ID}
python test.py > output_${SLURM_ARRAY_TASK_ID}.txt

# after the job is done we copy our output back to $SLURM_SUBMIT_DIR
cp output_${SLURM_ARRAY_TASK_ID}.txt ${SLURM_SUBMIT_DIR}

# we step out of the scratch directory and remove it
cd ${SLURM_SUBMIT_DIR}
rm -rf ${SCRATCH_DIRECTORY}

# happy end
exit 0