Parallel MATLAB

  • MathWorks: How do I run MATLAB in batch mode on a UNIX machine? www
  • MathWorks: Is it possible to pass a MATLAB file that requires an input argument to MATLAB in batch mode under UNIX? www
  • SGE environment variables www

At the UNIX command prompt, MATLAB can be run in a batch mode by piping in a script like matlab -nodisplay < myscript.m.

However, to run a set of parallel jobs, we need some way to pass in the current job index. MATLAB doesn't provide a way of doing this, itself, but we can get access to unix environment variables. The SGE cluster manager already stores the job array task ID as SGE_TASK_ID, so we are all set.

i = str2num(getenv('SGE_TASK_ID'));
sub_list = textread('subjects.txt', '%s');
matlab -nodisplay < testscript.m
matlab -nodisplay < testscript.m
matlab -nodisplay < testscript.m
matlab -nodisplay < testscript.m

Submit the job array with fsl_sub or a similar qsub wrapper: fsl_sub -t jobarray.txt

Check the output logs to make sure everything is working:

$ cat jobarray.txt.o1100366.2

                              < M A T L A B >
                  Copyright 1984-2007 The MathWorks, Inc.
                         Version (R2007a)
                              January 29, 2007

  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit
>> >> >> >> >> 
ans = 


>> >>
parallel_matlab.txt · Last modified: 2011/08/09 5:16 pm PDT by John Colby
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki