MATLAB

From FarmShare

(Difference between revisions)
Jump to: navigation, search
 
(32 intermediate revisions not shown)
Line 1: Line 1:
-
== getting list of available matlab versions ==
+
[https://www.mathworks.com/products/matlab.html MATLAB] is a multi-paradigm numerical computing environment and programming language.
-
You can run module spider matlab to get a list of available matlab versions
+
== Getting Started  ==
 +
 
 +
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.
<source lang="sh">
<source lang="sh">
-
$ module spider matlab
+
module spider matlab      
-
  --------------------------------------------------------------------------------------------------------------------
+
--------------------------------------------------------------------------------------------------------------------------------
   matlab:
   matlab:
-
  --------------------------------------------------------------------------------------------------------------------
+
--------------------------------------------------------------------------------------------------------------------------------
     Description:
     Description:
-
       MATLAB and toolboxes
+
       A multi-paradigm numerical computing environment and programming language.
     Versions:
     Versions:
-
         matlab/r2012b
+
         matlab/r2016b
-
         matlab/r2013a
+
         matlab/r2017a
-
  --------------------------------------------------------------------------------------------------------------------
+
--------------------------------------------------------------------------------------------------------------------------------
-
  To find detailed information about matlab please enter the full name.
+
</source>
-
  For example:
+
-
    $ module spider matlab/r2013a
+
Use <code>module load</code> to set up your environment, and then run <code>matlab</code> to start an interactive session.
-
  --------------------------------------------------------------------------------------------------------------------
+
 +
<source lang="sh">
 +
module load matlab
 +
matlab
 +
</source>
 +
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.
 +
 +
<source lang="sh">
 +
ssh -X sunetid@rice.stanford.edu
 +
module load matlab
 +
matlab &
</source>
</source>
 +
== Running MATLAB in Batch Mode ==
-
==first steps==
+
If you have prepared MATLAB code as a program (<code>.m</code>) file you can run it non-interactively.
-
Per [[FarmShare software]] try something like:
+
<source lang="sh">matlab -nodesktop < program.m</source>
 +
 
 +
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.
 +
 
 +
<source lang=sh>
 +
#!/bin/bash
-
<source lang="sh">
 
-
module avail
 
module load matlab
module load matlab
 +
matlab -nodesktop << EOF
 +
  % MATLAB code
 +
EOF
</source>
</source>
-
If you're running MATLAB for the first time, it'll try to write some stuff into $HOME/.matlab so make sure you have your [[AFS]] tokens or else MATLAB will crash with an undecipherable error message.
+
== Using MDCS ==
-
As of 9/22/2013 this works on the corn.stanford.edu cluster but NOT on the myth.stanford.edu cluster.
+
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.
-
==interactive MATLAB==
+
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>.
 +
<source lang="matlab">
 +
c = parcluster;
 +
j = c.batch(@pwd, 1, {}, 'Pool', 4);
 +
j.State
 +
j.fetchOutputs{:}
 +
</source>
-
[[Matlab-interactive]]
+
For a more detailed walkthrough see [[Media:Getting_Started_with_Serial_and_Parallel_MATLAB.pdf|Getting Started with Serial and Parallel MATLAB]].
-
[[Matlab-parallel]]
+
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