An example of a Matlab non-interactive batch job on pegasus2 using the bsub utility.
In general, batch jobs can be run using matlab with the following syntax: "matlab < job_script.m". This syntax can be used with the bsub utilty to submit jobs to the cluster.
Here is an example job script that we'll run (bsub_example.m).
%=====================================================================
% BSUB Example: Do nothing. Print datestamp to show
% how it's going.
%
% Art Gleason July 14, 2014
%=====================================================================
N = 20; % bump this up if you want a longer job
for ix=1:N
ixstamp = sprintf('Iteration %d at %s\n', ix, datestr(now));
disp(ixstamp);
pause(5);
end
Hhere is the script we'll submit to bsub to start the job (bsub_bsub.job)
#!/bin/bash #BSUB -J BSUBexample #BSUB -o %J.out #BSUB -e %J.err #BSUB -W 00:10 #BSUB -q debug #BSUB -n 1 # ### Run job # cd not needed if CWD is the right one when this is submitted # In other words, cd to the dir containing bsub_example.m first # Note: it IS needed to module load matlab before submitting this matlab < bsub_example.m >& bsub_example.log
Put all of these files in the same directory, then cd into that directory. Make sure to "module load matlab". Then, submit the job with:
login6 267% bsub < bsub_bsub.job Job <1083478> is submitted to queue.
You can check on the status of the job with the bjobs command:
login6 268% bjobs 1083478 agleaso RUN debug login6.pega n202.pegasu *UBexample Jul 15 16:23
Another way to see how your job is running is to use lmstat to see the status of the matlab licenses. I alias this command to make it easier to use:
login6 272% which lmstat
lmstat: aliased to /share/opt/MATLAB/R2013a/etc/lmstat -S MLM -c /share/opt/MATLAB/R2013a/licenses/network.lic
login6 271% lmstat
------------------------------------------------------------------
lmstat - Copyright (c) 1989-2012 Flexera Software LLC. All Rights Reserved.
Flexible License Manager status on Tue 7/15/2014 16:24
License server status: 28518@m2
License file(s) on m2: /share/opt/flexlm/server.lic:
m2: license server UP (MASTER) v11.11
Vendor daemon status (on m2):
MLM: UP v11.11
Feature usage info:
Users of MATLAB: (Total of 6901 licenses issued; Total of 1 licenses in use)
"MATLAB" v31, vendor: MLM
floating license
agleason n202 /dev/tty (v29) (m2/28518 7219), start Tue 7/15 16:23
Users of SIMULINK: (Total of 6901 licenses issued; Total of 0 licenses in use)
Users of Aerospace_Blockset: (Total of 6901 licenses issued; Total of 0 licenses in use)
..... Note: there will be many more lines here, one for each
of the matlab toolboxes that are available.... I have cut them
out for space....
What you can see from the above is that the job started on note n202 and that it checked out one copy of matlab (see the agleason n202 line under lmstat). That's good. If your job uses some other toolboxes you should see a license checked out for each toolbox used.
When the job finishes, it will disappear from the bjobs listing. You should find a file "bsub_example.log" that looks like this:
login6 276% cat bsub_example.log
Warning: No display specified. You will not be able to display graphics on the screen.
Warning: No window system found. Java option 'MWT' ignored.
< M A T L A B (R) >
Copyright 1984-2013 The MathWorks, Inc.
R2013a (8.1.0.604) 64-bit (glnxa64)
February 15, 2013
No window system found. Java option 'MWT' ignored.
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> >> >> >> >> >> >> >> >> Iteration 1 at 15-Jul-2014 16:24:03
Iteration 2 at 15-Jul-2014 16:24:09
Iteration 3 at 15-Jul-2014 16:24:14
Iteration 4 at 15-Jul-2014 16:24:19
Iteration 5 at 15-Jul-2014 16:24:24
Iteration 6 at 15-Jul-2014 16:24:29
Iteration 7 at 15-Jul-2014 16:24:34
Iteration 8 at 15-Jul-2014 16:24:39
Iteration 9 at 15-Jul-2014 16:24:44
Iteration 10 at 15-Jul-2014 16:24:49
Iteration 11 at 15-Jul-2014 16:24:54
Iteration 12 at 15-Jul-2014 16:24:59
Iteration 13 at 15-Jul-2014 16:25:04
Iteration 14 at 15-Jul-2014 16:25:09
Iteration 15 at 15-Jul-2014 16:25:14
Iteration 16 at 15-Jul-2014 16:25:19
Iteration 17 at 15-Jul-2014 16:25:24
Iteration 18 at 15-Jul-2014 16:25:29
Iteration 19 at 15-Jul-2014 16:25:34
Iteration 20 at 15-Jul-2014 16:25:39
Note how each iteration is (a) sequential and (b) 5 seconds apart. Compare this with the output using either of the other two methods.
To run many similar jobs in parallel using this technique, make different scripts for each job and submit as many jobs as you need. Remember each will use one CPU.