MATLAB

From FarmShare

(Difference between revisions)
Jump to: navigation, search
m
 
(73 intermediate revisions not shown)
Line 1: Line 1:
-
We don't have a license for MATLAB Distributed Compute Server (MDCS aka MDCE).  
+
[https://www.mathworks.com/products/matlab.html MATLAB] is a multi-paradigm numerical computing environment and programming language.
-
We do have the Parallel Computing Toolbox, you can use that to parallelize your job across multiple cores in a single machine.
+
== Getting Started  ==
-
Here's how to write a job using MDCS: http://docs.uabgrid.uab.edu/wiki/MatLab_CLI#Parallel_MATLAB
+
Run <code>module avail</code> to get a list of all software modules, or <code>module spider</code> to get a list of available versions of MATLAB.
-
You can use the "maxNumCompThreads" command (deprecated) to see how many parallel threads you can run. I get "24" on barley, or "8" on corn.
+
<source lang="sh">
 +
module spider matlab     
-
== simple PCT run  ==
+
--------------------------------------------------------------------------------------------------------------------------------
-
<pre>/afs/ir.stanford.edu/software/matlab-2011b/bin/matlab -nodesktop -r 'maxNumCompThreads'
+
  matlab:
 +
--------------------------------------------------------------------------------------------------------------------------------
 +
    Description:
 +
      A multi-paradigm numerical computing environment and programming language.
-
&gt;&gt; matlabpool ( 'open', 'local', 8)
+
    Versions:
-
Starting matlabpool using the 'local' configuration ... connected to 8 labs.
+
        matlab/r2016b
-
&gt;&gt;
+
        matlab/r2017a
-
&gt;&gt; matlabpool size
+
-
ans =
+
--------------------------------------------------------------------------------------------------------------------------------
 +
</source>
-
    8
+
Use <code>module load</code> to set up your environment, and then run <code>matlab</code> to start an interactive session.
-
Then use 'parfor' instead of 'for'.
+
<source lang="sh">
-
</pre>  
+
module load matlab
-
matlabpool of size 0 and size 1 are effectively the same, except the latter uses a PCT toolbox license.
+
matlab
 +
</source>
-
Here are some training slides and example code that I copied from http://www.osc.edu/~samsi/sc11edu/  
+
If you have not configured a [https://srcc.stanford.edu/farmshare2/connecting remote display] MATLAB will start in text-mode, but the MATLAB desktop is also supported.
-
*http://stanford.edu/~chekh/matlab.tar
+
<source lang="sh">
 +
ssh -X sunetid@rice.stanford.edu
 +
module load matlab
 +
matlab &
 +
</source>
-
== example single matlab file run via qsub  ==
+
== Running MATLAB in Batch Mode ==
-
Here's our helloworld.m:
+
If you have prepared MATLAB code as a program (<code>.m</code>) file you can run it non-interactively.
-
<pre>disp('Hello World');
+
-
</pre>  
+
-
Here's a command to run that.  
+
-
  /afs/ir.stanford.edu/software/matlab-2011b/bin/matlab -nodesktop &lt; helloworld.m
+
<source lang="sh">matlab -nodesktop < program.m</source>
-
We want to run this same command via the job scheduling system. Let's write a job script.  
+
You can use this method to submit a MATLAB job to a compute node, and you can even include MATLAB code in-line in an <code>sbatch</code> script.
-
<pre>$ cat matlab_example.script
+
 
 +
<source lang=sh>
#!/bin/bash
#!/bin/bash
-
#$ -N matlab_example
+
module load matlab
-
#$ -m bes
+
matlab -nodesktop << EOF
-
#$ -M chekh@stanford.edu
+
  % MATLAB code
-
 
+
EOF
-
/afs/ir.stanford.edu/software/matlab-2011b/bin/matlab -nodesktop &lt; /afs/ir/users/c/h/chekh/helloworld.m
+
</source>
-
</pre>  
+
-
Submit the script:
+
-
 
+
-
  qsub matlab_example.script
+
-
Look at the job status:
+
== Using MDCS ==
-
  qstat
+
MATLAB Distributed Computing Server is supported, and you can submit jobs using up to 127 workers. To set up the cluster, load the <code>matlab</code> module, start MATLAB, and run <code>configCluster</code>. This only needs to be done once.
-
You should get output file like matlab_example.oXXXXX
+
Once the cluster has been configured, commands like <code>parcluster</code> should use cluster (rather than local) workers by default. You can get a handle to the cluster using the <code>parcluster</code> command, submit jobs using <code>batch</code> (which returns a handle to the job), and query job state and results using <code>State</code> and <code>fetchOuputs</code>.
-
<pre>Warning: No display specified. You will not be able to display graphics on the screen.
+
-
Warning: No window system found. Java option 'MWT' ignored
+
-
                            &lt; M A T L A B (R) &gt;
+
<source lang="matlab">
-
                  Copyright 1984-2011 The MathWorks, Inc.
+
c = parcluster;
-
                    R2011b (7.13.0.564) 64-bit (glnxa64)
+
j = c.batch(@pwd, 1, {}, 'Pool', 4);
-
                              August 13, 2011
+
j.State
 +
j.fetchOutputs{:}
 +
</source>
-
+
For a more detailed walkthrough see [[Media:Getting_Started_with_Serial_and_Parallel_MATLAB.pdf|Getting Started with Serial and Parallel MATLAB]].
-
To get started, type one of these: helpwin, helpdesk, or demo.
+
-
For product information, visit www.mathworks.com.
+
-
+
-
&gt;&gt; Hello World
+
-
</pre>
+
-
----
+
-
Search the farmshare-discuss archives for posts about&nbsp;[https://mailman.stanford.edu/mailman/swish?query=Matlab&submit=Search+farmshare-discuss+%21&listname=farmshare-discuss&metaname=swishdefault&sort=unixdate Matlab].
+
Please note that, while multi-node jobs are supported, FarmShare does not have a fast interconnect, so code that requires a lot of communication or synchronization between workers may not fully realize any expected improvement in performance. You may want to restrict your MDCS jobs to a single node, or to 15 (or fewer) workers, when possible.

Latest revision as of 16:46, 15 February 2018

MATLAB is a multi-paradigm numerical computing environment and programming language.

Getting Started

Run module avail to get a list of all software modules, or module spider to get a list of available versions of MATLAB.

module spider matlab       

--------------------------------------------------------------------------------------------------------------------------------
  matlab:
--------------------------------------------------------------------------------------------------------------------------------
    Description:
      A multi-paradigm numerical computing environment and programming language.

     Versions:
        matlab/r2016b
        matlab/r2017a

--------------------------------------------------------------------------------------------------------------------------------

Use module load to set up your environment, and then run matlab to start an interactive session.

module load matlab
matlab

If you have not configured a remote display MATLAB will start in text-mode, but the MATLAB desktop is also supported.

ssh -X sunetid@rice.stanford.edu
module load matlab
matlab &

Running MATLAB in Batch Mode

If you have prepared MATLAB code as a program (.m) file you can run it non-interactively.

matlab -nodesktop < program.m

You can use this method to submit a MATLAB job to a compute node, and you can even include MATLAB code in-line in an sbatch script.

#!/bin/bash

module load matlab
matlab -nodesktop << EOF
  % MATLAB code
EOF

Using MDCS

MATLAB Distributed Computing Server is supported, and you can submit jobs using up to 127 workers. To set up the cluster, load the matlab module, start MATLAB, and run configCluster. This only needs to be done once.

Once the cluster has been configured, commands like parcluster should use cluster (rather than local) workers by default. You can get a handle to the cluster using the parcluster command, submit jobs using batch (which returns a handle to the job), and query job state and results using State and fetchOuputs.

c = parcluster;
j = c.batch(@pwd, 1, {}, 'Pool', 4);
j.State
j.fetchOutputs{:}

For a more detailed walkthrough see Getting Started with Serial and Parallel MATLAB.

Please note that, while multi-node jobs are supported, FarmShare does not have a fast interconnect, so code that requires a lot of communication or synchronization between workers may not fully realize any expected improvement in performance. You may want to restrict your MDCS jobs to a single node, or to 15 (or fewer) workers, when possible.

Personal tools
Toolbox
LANGUAGES