Computational Science Community Wiki

Running Matlab on Mace01

A Simple Example

Here is an example SGE submission script for use with Matlab — we assume it is saved as runmatlab.sh:

#$ -cwd
    #
    # ...use the current working directory --- from where you type
    #    "qsub runmatlab.sh" --- to run the job...
    #

#$ -q serial.q
    #
    # ...tell SGE to run the job within the "serial.q" queue...
    #

/software/matlab/bin/matlab < myinput.m
    #
    # ...the job consists of running the above command, i.e., run
    #    Matlab in batch mode with "myinput.m" as the input file/script...

The Matlab input file/script is simply a list of Matlab commands, such as

    x=1:5
    y=x.^2
    plot(x,y)
    saveas(gcf, 'myfig', 'fig')

To submit the job to the batch system:

    prompt> qsub runmatlab.sh

With the SGE submission script given above, standard output from the job, i.e., "screen" output, is sent to matlab_output, viz

    Warning: No display specified.  You will not be able to display graphics on the screen.

                              < M A T L A B >
                  Copyright 1984-2007 The MathWorks, Inc.
                         Version 7.5.0.338 (R2007b)
                               August 9, 2007

    To get started, type one of these: helpwin, helpdesk, or demo.
    For product information, visit www.mathworks.com.

    >>
    x =

        1     2     3     4     5

    >>
    y =

        1     4     9    16    25

    >> 

With the Matlab input file/script given above, the graphic is output to a file called myfig.fig as specified in the saveas command.