This section illustrates how to submit a small, serial, MATLAB program as a job to a batch queue. This MATLAB program prints the name of the run host and gets three random numbers.
Prepare a MATLAB script myscript.m, and a MATLAB function file myfunction.m:
% FILENAME: myscript.m
% Display name of compute node which ran this job.
[c name] = system('hostname');
fprintf('\n\nhostname:%s\n', name);
% Display three random numbers.
A = rand(1,3);
fprintf('%f %f %f\n', A);
quit;
% FILENAME: myfunction.m
function result = myfunction ()
% Return name of compute node which ran this job.
[c name] = system('hostname');
result = sprintf('hostname:%s', name);
% Return three random numbers.
A = rand(1,3);
r = sprintf('%f %f %f', A);
result=strvcat(result,r);
end
Also, prepare a job submission file, here named myjob.sub. Run with the name of the script:
#!/bin/bash# FILENAME: myjob.subecho"myjob.sub"# Load module, and set up environment for Matlab to runmoduleloadmatlab
unsetDISPLAY
# -nodisplay: run MATLAB in text mode; X11 server not needed# -singleCompThread: turn off implicit parallelism# -r: read MATLAB program; use MATLAB JIT Accelerator# Run Matlab, with the above options and specifying our .m filematlab-nodisplay-singleCompThread-rmyscript