Harvard |  FAS |  GSAS |  Division of Science |  HUIT 

LSF: Running Pre-Installed Software Packages in Batch

 

LSF cheat sheet

This page describes how to run R, IDL, Matlab, or Mathematica “batch” jobs, i.e., long jobs that you submit to run while you go away from the computer. If, on the other hand, you want to run these programs interactively, go to the Interactive queue FAQ.

Please use the queue short_serial for jobs that are short (less than 1 hour long). If the job will take longer (but less than 24 hours), then use the queue normal_serial. If the job will require greater than 24 hours, then use the queue long_serial. The short_serial has highest priority, normal_serial lower and long_serial lowest priority.

R

To submit a batch R job, first prepare a file with your R commands, say “program_file.R”. Then issue the two commands:

module load math/R-2.12.0
bsub -q short_serial R CMD BATCH program_file.R output_file.txt

The latter command submits a batch job to the batch queue taking input from the file program_file.R, and placing text output in output_file.txt. Graphical output is saved to a PDF file via the “pdf” command within R, for example:

pdf(“graphs.pdf”) # create graphical output file
X=rnorm(100) # generate 100 N(0,1) variates
Y=rexp(100) # generate 100 Exp(1) variates
c(mean(X),mean(Y)) # mean of both samples
hist(X) # plot N(0,1) histogram
hist(Y) # plot Exp(1) histogram
dev.off() # close the file

Both histograms are saved to the same PDF file (one graph per page).

Matlab

To submit a batch Matlab job, first prepare a file with your Matlab commands, say “program_file.m”. Then issue the two commands:

module load math/matlab-R2010b
bsub -q short_serial matlab -nodisplay -nojvm -nosplash -r program_file -logfile output_file.txt

NB: if you intend to use java programs do not include the flag -nojvm.

Note that the suffix “.m” is omitted from the command file name. This submits a batch job to the batch queue taking input from the file program_file.m, and placing text output in output_file.txt. Graphical output is saved to a PDF file via the “print -dpdf” command within Matlab, for example:

f = @(x) 3.5.^(-0.5*x).*cos(6*x);
ezplot(f,[-2,4,-3,3])
print -dpdf f.pdf
print -dpsc fgh.ps
randperm(15)
g = ezplot3(‘sin(t)’,'cos(t)’,'t’,[0,6*pi]);
set(g, ‘Color’,'r’,'Linestyle’,'-’,'LineWidth’,2);
print -dpdf g.pdf
print -dpsc fgh.ps -append
h = @(x,y) 100*(y-x.^2).^2+(1-x).^2;
ezsurf(h)
print -dpdf h.pdf
print -dpsc fgh.ps -append

It is not possible to insert multiple figures in a PDF file. A workaround for this is to insert multiple figures in a (color) PS file via the “print -dpsc” command using the -append option. Postscript files can, in turn, be converted to PDF via www.ps2pdf.com or Adobe Distiller.

Mathematica

To submit a batch Mathematica job, first prepare a file with your Mathematica commands, say “test.m”. Then issue the two commands:

module load hpc/mathematica-7.0
bsub -q short_serial “math < test.m > test-out.txt”

Note that the suffix “.m” is included in the command file name. This submits a batch job to the batch queue taking input from the file test.m, and placing text output in test-out.txt.

Saving graphical output is somewhat trickier. To illustrate the simplest approach, here is a sample Mathematica job:

AppendTo[$Echo, "stdout"]

3+5
Integrate[Exp[-x^2],{x,-Infinity,Infinity}]

FactorInteger[120]

sc = Plot[{Sin[x], Cos[x]}, {x, 0, 2*Pi}, PlotStyle -> {
{RGBColor[1, 0, 0], Thickness[0.01]},
{RGBColor[0, 1, 0], Thickness[0.01]}}]

Export["sc.m",sc,"TEXT"]

abc=Table[Plot[x^n,{x,0,1}], {n, 1, 3}]

Do[Export["abc"<>ToString[n]<>”.m”,abc[[n]],”TEXT”],{n,1,3}]

7+9
Quit

Four additional files (sc.m, abc1.m, abc2.m & abc3.m) are created when running this program. These can be subsequently converted to plots on a local copy of Mathematica (on your laptop, for example), assuming this is available.

Less simple is exporting graphics directly to PDF or JPG files in batch mode, because even though Mathematica is not displaying anything, it still needs the graphical front end running.

On Odyssey, this means that you must have an X display setup. In that case, Mathematica will automatically run the front end and exporting will work. If you are connecting to Odyssey from Linux or a Mac with X11 installed, merely use ssh -Y. If you are connecting from Windows, you must use Cygwin, Xming or X-Win32 to run an X server in order to do the same.

IDL

Batch jobs can be run within IDL as follows. Prepare a file with your IDL commands, say “sample.pro”:

pro sample
openw, 1, ‘permut.txt’
x = lindgen(10)
x = x[sort(randomu(seed,10))]

printf, 1, x
close, 1
set_plot,’PS’
device, filename=’surf_wire.ps’
a = findgen(35)
b = 45 – findgen(45)
c = a # b
surface, c
device, /close
return
end

Note the opening and closing statements. Call the compilation at the IDL prompt via:

IDL> .compile sample

and then run the program:

IDL> sample

Text output is saved to permut.txt and graphical output is saved to surf_wire.ps. Postscript files, as such, can be converted to PDF via www.ps2pdf.com or Adobe Distiller.

The same IDL batch job can be run in LSF simply via:

module load hpc/IDL-7.0
bsub -q short_serial idl CMD BATCH sample

Note that the suffix “.pro” is omitted from the command file name.

Site last updated May 23, 2013