Matlab

Below is a fairly basic job script that uses Matlab R2022b to run a Matlab .m script called matlab_script.m

A copy of this file is available on cluster in the path /shared/hpc/sample-job-scripts/matlab/sample-matlab-script.sh

Copy that file to your work directory and rename it to whatever you'd like.  Here we've used the name matlab_job1.sh:

cp /shared/hpc/sample-job-scripts/matlab/sample-matlab-script.sh matlab_job1.sh

Then, you'll need to edit the file to suit your needs.  Once you've saved your changes, you can use the sbatch program to submit the job:

sbatch matlab_job1.sh

 

The sample script is below:


#!/bin/bash

# This is a simple Matlab job script example.  
# IMPORTANT.  You will need to edit the job parameters to suit your needs.
# All lines that begin with #SBATCH are job parameters that are read by the sbatch program when you submit the job.

# The --job-name is the name of the job as it appears in the queue.
#SBATCH --job-name=matlab-job-1

# The --output parameter specifies the file where standard output from your job
# will be written.  (Messages from Matlab itself may be written to a different file, depending on how you run Matlab.)  
#SBATCH --output=OUTPUT

# The --output parameter specifies the file where standard errors from your job
# will be written.
#SBATCH --error=ERRORS

# The --nodes parameter specifies the number of nodes you are requesting for the job.
#SBATCH --nodes=1

# The --ntasks parameter specifies the total number of cores your job will need. 
# If you request 4 nodes with 16 cores on each node, set ntasks to 64.
#SBATCH --ntasks=16

# specify the time you expect the job to run.  For 10 hours, set time to 10:00:00. 
#SBATCH --time=10:00:00

# Specify the e-mail address you would like job status e-mails to be sent to.
#SBATCH --mail-user=someuser@iastate.edu

# Specify the types of job status messages you would like to receive.
#  BEGIN - send a message when the job starts.
#  FAIL - send a messages if the job fails.
#  END - send a message when the job runs to completion. 
#SBATCH --mail-type=BEGIN,FAIL,END

#  Start by going to the folder where the data for this job is located.
cd /work/mygroup_folder

# Module purge ensures that no other modules are loaded.
module purge

# Load the Matlab R2022b module.
module load matlab/R2022b

# Run matlab using the .m file called "matlab_script.m".  In this example, the output of Matlab 
# is written to the file called matlab_output.log.  
matlab  -batch matlab_script > matlab_output.log
# Note that you don't include the .m extension.  Matlab will add the .m extension when it resolves the file name.