Stern School of Business, New York University

Slurm Batch Example – matlab

We will soon turn of Sun Grid Engine and switch to slurm. The example below shows a script example that you can use to submit a slurm job with the sbatch command.



#!/bin/bash                                                                                                            
#                                                                                                                      
# mymatjob.sbatch                                                                                                         
#                                                                                                                      
# Sample shell script to run a matlab job under slurm.    \                                                                                                                                                                              
#                                                                                                                      
#  use sbatch mymatjob.sbatch to submit the job.                                                                       
#  Note, this shell script must be executable                                                                          
#  (i.e. chmod a+rx mymatjob.sh)                                                                                       
#                                                                                                                      
# the #SBATCH directives provide informatiom to SLURM about the job requirements                                       
#                                                                                                                      
#   Name the job mymatjob                                                                                              
#SBATCH --job-name=mymatjob                                                                                            
# request 1 node to run on (Currently, all that we allow on the Stern grid)                                            
#SBATCH --nodes=1                                                                                                      
# request 4 cores for processing                                                                                       
##SBATCH --cpus-per-task=4                                                                                             
# MAX Wall time to run                                                                                                 
# NOTE, NOT CPU TIME, 20 minutes of wall-time                                                                          
#SBATCH --time=00:20:00                                                                                                
# MEMORY - request 6GB of ram                                                                                          
#SBATCH --mem=6GB                                                                                                      
# Request the version of matlab                                                                                        
                                                                                    
# RUN the job                                                                                                          
module purge                                                                                                           
module load matlab/2019a                                                                                               
# Run the job ...                                                                                                      
echo "starting on host"                                                                                                
hostname                                                                                                               
# run matlab without all the startup options which take                                                                
# a long time starting up.                                                                                             
matlab   -nosplash -nodesktop -nojvm  -nodisplay < mymatjob.m