I am using slurm to submit jobs to the university supercomputer. My matlab function has one parameter:
function test(variable_1)
and my slurm file is (I am not sure if it is correct. I know how to define the value of the parameter in the slurm file, but I would like to pass the value to the slurm file as I need to run the matlab function many times with different values for the parameter):
#!/bin/bash -l
#SBATCH --time=2-00:00:00
#SBATCH --job-name="test"
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --mem=4gb
#SBATCH -p small
module load matlab/R2021a
matlab -nodisplay -nodesktop -nosplash -r "test variable_1"
I tried to use the following codes (for example, I would like to set variable_1=12) to submit the job but it did not work.
sbatch test.slurm 12
Can anyone help me with this issue? Thanks!
CodePudding user response:
The first argument of the Bash script is stored in an environment variable named $1
. So the last line of the script should be
matlab -nodisplay -nodesktop -nosplash -r "test $1"
Beware that if the argument is a number, you might need to first cast it to integer from string with str2num
in your Matlab script.