User Tools

Site Tools


matlab_usage

This is an old revision of the document!


Matlab Details and Tips

Default startup.m settings

If you need to replace the default CfN settings in your startup.m file, see /share/admin/matlab-startup-common.m on chead.

Matlab via qsub batch jobs

You may need to run Matlab scripts in a qsub job. It's fairly easy. This command will run a series of Matlab commands from the command line (shell), which we can use in a qsub job script:

matlab -nodisplay -r "a=[1 2 3]; disp(a); disp(a+1); exit" 

Explanation:

  • -nodisplay - this option tells Matlab to run in command-line mode, i.e. with no GUI windows
  • -r - this option tells Matlab to run the follow text as commands. This could be just the name of the matlab script (.m file) you want to run, for example. This text is the same as you would enter on the command line in the Matlab GUI window. Put a semicolon between commands.
  • exit - add 'exit' as the last command (e.g. after calling your matlab script) to make sure matlab exits when the script is finished

So if you put the above text in a file called matlabjob and run:

qsub matlabjob

you'll get the following output in your matlabjob.o<jobid> file (where <jobid> will be the job id of your run of qsub):

                                                < M A T L A B (R) >
                                      Copyright 1984-2013 The MathWorks, Inc.
                                        R2013a (8.1.0.604) 64-bit (glnxa64)
                                                 February 15, 2013

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

   2     3     4
   

Parallel Toolbox Considerations

Number of Workers

When using Matlab's Parallel Toolbox, you generally must specify the number of workers to match the number of OGS/SGE slots requested by your job. To programmatically get the number of slots you requested, you can use the NSLOTS shell environment variable, or the matlab 'maxNumCompThreads' command.

NOTE: Your jobs (qsub or qlogin) run on a single compute node for easier parallel processing, and each compute node has only 16 cores. So you don't want to ask for more than 16 slots (and thus matlab workers) for a job. But also note that asking for 16 slots meaning waiting for a compute node to be completely free before you can start your job.

NOTE: 'Workers' is not the same as 'number of threads'. Workers are like mini jobs that process something. By default they each use one thread/core. Implicit multithreading in Matlab is controlled by maxNumCompThreads, for inherently parallel operations like matrix multiplication.

See details of parallel processing.

Issue with MATLABPOOL in Multiple Matlab sessions

Why am I unable to start a local MATLABPOOL from multiple MATLAB sessions that use
a shared preference directory using Parallel Computing Toolbox?

See the discussion here, and in particular the solution provided in the comment by Andreas.

matlab_usage.1426705144.txt.gz · Last modified: 2015/03/18 18:59 by mgstauff