Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

(Note: '-n 1' is needed for srun command. It make sure only run one copy of the command.)

First create a script, in this example named myJob.shthat contains both the scheduler flags, with the usual format #SBATCH flag, and the commands to be executed. In this second example the command to be executed is date which will return the current date and time.

Similarly to the first example the date command is preceded by srun -n 1 to execute it as a single,separate slurm step so that the following sacct command can be used to report the job resource usage.

Code Block
#!/bin/bash
#SBATCH -p short           
#SBATCH -t 0-0:10:0
#SBATCH -o myJob.out
#SBATCH --mem=2G

unset SLURM_CPU_BIND
srun -n 1 date             
sleep 5                                 # wait for slurm to get the job status into its database
sacct --format=JobID,Submit,Start,End,State,Partition,ReqTRES%30,CPUTime,MaxRSS,NodeList%30 --units=M -j $SLURM_JOBID

...

Code Block
#!/bin/bash
#SBATCH -p short           
#SBATCH -t 0-0:10:0
#SBATCH -o myJob.out
#SBATCH --mem=2G

unset SLURM_CPU_BIND
srun -n 1 your_first_command_here
srun -n 1 your_second_command_here
srun -n 1 your_third_command_here
             
sleep 5                                 # wait for slurm to get the job status into its database
sacct --format=JobID,Submit,Start,End,State,Partition,ReqTRES%30,CPUTime,MaxRSS,NodeList%30 --units=M -j $SLURM_JOBID

...

Code Block
sbatch MyJob.sh      # where MyJob.sh is a text file containing:


#-----------------------
#!/bin/bash
#SBATCH -p short           
#SBATCH -t 0-0:10:0
#SBATCH -o myJob.out
#SBATCH --mem=2G

unset SLURM_CPU_BIND
srun -n 1 this_is_an_error
srun -n 1 date
             
sleep 5                                 # wait for slurm to get the job status into its database
sacct --format=JobID,Submit,Start,End,State,Partition,ReqTRES%30,CPUTime,MaxRSS,NodeList%30 --units=M -j $SLURM_JOBID

...

Code Block
sbatch MyJob.sh      # where MyJob.sh is a text file containing:


#-----------------------
#!/bin/bash
#SBATCH -p short           
#SBATCH -t 0-0:10:0
#SBATCH -o myJob.out
#SBATCH --mem=2G

unset SLURM_CPU_BIND
srun -n 1 bash -c "this_is_an_error || scancel $SLURM_JOBID "
srun -n 1 bash -c "date || scancel $SLURM_JOBID "
             
sleep 5                                 # wait for slurm to get the job status into its database
sacct --format=JobID,Submit,Start,End,State,Partition,ReqTRES%30,CPUTime,MaxRSS,NodeList%30 --units=M -j $SLURM_JOBID

...