Using System() to submit cluster job to SLURM but gives "sbatch: command not found" error.

12 views (last 30 days)
I am converting a code written for LSF workload manager to a cluster that uses SLURM. The MATLAB code includes a line that submit a .sh job script to the cluster (linux), so I changed the 'bsub' command for LSF to 'sbatch' for SLURM. However, the 'command not found' error still pops out.
One way to get rid of the erro is to add the trailing character '&' at the end of the system command as suggested on the website . However, although the error no longer pops out and the 'status=0' is shown (which usually means program runs correctly), the output file the .sh file is suppose to write does not appear.
strFn_O = '/dev/null';
strFn_E = '/dev/null';
sysClusterCmd = ['$ sbatch --ntasks=1 --job-name=007 --output=' strFn_O ' --error=' strFn_E ' &'];
My question would be, how to change the code to write the output file in the correct folder?
I use a shell to invoke the matlab that again invoke a shell. Is that a problem?

Answers (1)

Raymond Norris
Raymond Norris on 22 Oct 2022
I suspect the command not found is for sbatch. If so, I would suggest hardcoding the location of it in your path. For example
sysClusterCmd = ['$ /path/to/slurm/bin/sbatch --ntasks=1
With that said, I don't know what the leading "$" is for. Have you tried removing it?
Also, programatically, I would suggest calling system as such (for example)
[FAILED, result] = system(sysClusterCmd);
if FAILED~=false
% Command failed. Display "result" in an error.


Find more on Cluster Configuration in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!