This batch job will run the matlab_training_array.m code with parameters 3,4 and 5 which are given in the #SBATCH --array=3-5 and all will run at the same time. UNIV1S16 is the slurm-account-name. #SBATCH --account=UNIV1S16
#!/bin/bash
#SBATCH --nodes=1 # Run all processes on a single node
#SBATCH --ntasks=1 # Run a single task
#SBATCH --cpus-per-task=1 # Number of CPU cores per task
#SBATCH --mem=4gb # Total memory limit
#SBATCH --time=01:00:00 # Time limit hrs:min:sec
#SBATCH --account=UNIV1S16 # Project name (RS00000, ECON0001, MAT0001 ...)
#SBATCH --partition=qCPU24 # partition requested (qBF, qTRD , qECON ...)
#SBATCH --output=output_%j.out
#SBATCH --error=error_%j.out
#SBATCH --mail-type=END,FAIL
#SBATCH --mail-user=stimsina@gsu.edu
#SBATCH --array=3-5
echo $SLURM_ARRAY_TASK_ID
# copy code and data to the scratch folder. Right now we have matlab code inside our project folder in Globus.
# And we are copying from project folder to the /scratch folder on cluster.
cp $IRODS_PROJECT/UNIV1S16/matlab_training_array.m $SCRATCH
# go to the folder where you copied your code and data
cd $SCRATCH
# load the software module needed
module load matlab/R2022a
# run the code
matlab -nodesktop -r "matlab_training_array($SLURM_ARRAY_TASK_ID)"
# copy the output back to the globus
mkdir -p $IRODS_PROJECT/UNIV1S16/$SLURM_JOB_ID
cp ~/output_$SLURM_JOB_ID.out $IRODS_PROJECT/UNIV1S16/$SLURM_JOB_ID
cp ~/error_$SLURM_JOB_ID.out $IRODS_PROJECT/UNIV1S16/$SLURM_JOB_ID
# remove the folder where processing is done once processing is completed
rm -rf $SCRATCH
This matlab code will take parameter 3, 4 and 5 given above in the sbatch script and give the output for 3, 4 and 5 variables
function matlab_training_array(num)
a = num;
b = a*a;
c = a*a*a;
d = sqrt(a);
disp(a);
disp(b);
disp(c);
disp(d);
end
$ ls
matlab_job_array.sh matlab_training_array.m
$ sbatch matlab_job_array.sh
Submitted batch job 2193968
We can see three jobs are running at the same time.
$ sacct -j 2193968
JobID JobName Partition Account AllocCPUS State ExitCode
------------ ---------- ---------- ---------- ---------- ---------- --------
2193968_3 matlab_jo+ qCPU24 univ1s16 1 RUNNING 0:0
2193968_3.b+ batch univ1s16 1 RUNNING 0:0
2193968_3.e+ extern univ1s16 1 RUNNING 0:0
2193968_4 matlab_jo+ qCPU24 univ1s16 1 RUNNING 0:0
2193968_4.b+ batch univ1s16 1 RUNNING 0:0
2193968_4.e+ extern univ1s16 1 RUNNING 0:0
2193968_5 matlab_jo+ qCPU24 univ1s16 1 RUNNING 0:0
2193968_5.b+ batch univ1s16 1 RUNNING 0:0
2193968_5.e+ extern univ1s16 1 RUNNING 0:0
Output files for each of the three jobs: 3, 4 and 5
$ cat output_2193968.out
5
MATLAB is selecting SOFTWARE OPENGL rendering.
< M A T L A B (R) >
Copyright 1984-2022 The MathWorks, Inc.
R2022a Update 4 (9.12.0.2009381) 64-bit (glnxa64)
July 7, 2022
To get started, type doc.
For product information, visit www.mathworks.com.
5
25
125
2.2361
$ cat output_2193969.out
3
MATLAB is selecting SOFTWARE OPENGL rendering.
< M A T L A B (R) >
Copyright 1984-2022 The MathWorks, Inc.
R2022a Update 4 (9.12.0.2009381) 64-bit (glnxa64)
July 7, 2022
To get started, type doc.
For product information, visit www.mathworks.com.
3
9
27
1.7321
$ cat output_2193970.out
4
MATLAB is selecting SOFTWARE OPENGL rendering.
< M A T L A B (R) >
Copyright 1984-2022 The MathWorks, Inc.
R2022a Update 4 (9.12.0.2009381) 64-bit (glnxa64)
July 7, 2022
To get started, type doc.
For product information, visit www.mathworks.com.
4
16
64
2