Skip to content

Matlab Example

Yoel Sanchez Araujo edited this page Aug 3, 2018 · 4 revisions

If I have a matlab file I want to submit as a job to be run on spock, with the file looking like:

function job_sample

done =1;
fprintf('done is %d\n',done);

end

and I save the file to the path /path/file.m

as a minimal example, you can create a script, say you name it (you can name it) run_mat.sh, and it's full path is /path/to/run_mat.sh and inside it, it has the contents below:

#!/bin/bash

#SBATCH --mem=4G
#SBATCH --time=01:00:00

matlab -nodesktop -nojvm -nodisplay -r /path/file.m

then you can submit it using this command:

sbatch /path/to/run_mat.sh

using job arrays

example bash file:

#!/bin/bash
#SBATCH --job-name=arrayJob
#SBATCH --output=arrayJob_%A_%a.out
#SBATCH --error=arrayJob_%A_%a.err
#SBATCH --array=4,5,6,7,8,9
#SBATCH --time=01:00:00
#SBATCH --ntasks=1
#SBATCH --mem-per-cpu=10000

module load matlab/R2016b
cd /jukebox/daw/yoel
echo "my SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
matlab -nojvm -nodisplay -r "s_num=$SLURM_ARRAY_TASK_ID;run_my_batch(s_num);quit"

then i just renamed the script that runs it to "run_my_batch", and inside it wrapped it with a function "run_my_batch"

Clone this wiki locally