wiki:cypress/Matlab

Version 15 (modified by bstreicher, 5 years ago) ( diff )

--

MATLAB

MATLAB (matrix laboratory) is a proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, and creation of user interfaces.

You can run your Matlab codes on Cypress clusters but you can't use GUI(Graphical User Interface) on computing nodes.

See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab

Running MATLAB interactively

Start an interactive session,

Error: Failed to load processor bash
No macro or processor named 'bash' found

Load the module

Error: Failed to load processor bash
No macro or processor named 'bash' found

Run MATLAB on the command-line window,

Error: Failed to load processor bash
No macro or processor named 'bash' found

You will get to the MATLAB command-line and can run MATLAB code here but no graphics.

Running MATLAB interactively with GUI

If you have x-window environment on the local machine, you can forward the Matlab GUI window from Cypress to your local screen. See X-window forwarding.

  1. Login to Cypress with X-window forwarding.
    ssh -Y userID@cypress.tulane.edu
    
  2. Start an interactive session.
    idev
    
  3. Load module
    module load matlab
    
  4. Run Matlab
    matlab &
    

Note that your Matlab session will be killed when the session time exceeds the walltime limit.

Running MATLAB in a batch mode

You can also submit your MATLAB job to the batch nodes (compute nodes) on Cypress. To do so, please first make sure that the MATLAB module has been loaded, and then launch "matlab" with the "-nodesktop -nodisplay -nosplash" option as shown in the sample SLURM job script below.

Error: Failed to load processor bash
No macro or processor named 'bash' found

See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab

Compiled Matlab

Compiling Matlab Scripts using mcc

Start an interactive session with idev, load the intel-psxe module (if you want to use mkl and multithreading), load the matlab module

[tulaneID@cypress1 ~]$ idev
Requesting 1 node(s)  task(s) to normal queue of defq partition
1 task(s)/node, 20 cpu(s)/task, 2 MIC device(s)/node
Time: 0 (hr) 60 (min).
Submitted batch job 80102
JOBID=80102 begin on cypress01-036
--> Creating interactive terminal session (login) on node cypress01-036.
--> You have 0 (hr) 60 (min).
--> Assigned Host List : /tmp/idev_nodes_file_tulaneID
Last login: Tue Sep 22 16:27:39 2015 from cypress1.cm.cluster
[tulaneID@cypress01-036 ~]$ module load intel-psxe
[tulaneID@cypress01-036 ~]$ module load matlab
[tulaneID@cypress01-036 ~]$ 

cd to the directory containing your matlab file and compile using matlabs C compiler mcc -m <your matlab .m file>. If your script is spread over many files you need to specify the directories containing those files mcc -m -I <source directory> <your matlab .m file>. For example, to compile my_script.m which depends on other .m files located in /home/tulaneID/myMatlab I would run

mcc -m -I /home/tulaneID/myMatlab my_script.m

This will compile files that my_script.m depends upon provided they are in /home/tulaneID/myMatlab

To see help,

mcc -?

Executing Compiled scripts

The above will create a binary executable named my_script. To run the executable as a SLRUM Job, just include the matlab module in your SLURM script. This will provide all the necessary libraries. For example,

Error: Failed to load processor bash
No macro or processor named 'bash' found

Running MATLAB in Parallel with Multithreads

MATLAB supports multithreaded computation for a number of functions and expressions that are combinations of element-wise functions. These functions automatically execute on multiple threads if data size is large enough. Note that on Cypress, in default, MATLAB runs with a single threads, and you have to explicitly specify the number of threads in your code. For example,

Error: Failed to load processor matlab
No macro or processor named 'matlab' found

In above code, the line,

Error: Failed to load processor matlab
No macro or processor named 'matlab' found

defines the number of threads. The environmental variable, SLURM_JOB_CPUS_PER_NODE has the value set in SLURM script, for example,

Error: Failed to load processor bash
No macro or processor named 'bash' found

The number of cores per process (task) is set by --cpus-per-task=10. This value goes to SLURM_JOB_CPUS_PER_NODE and you can use it to determine the number of threads used in the code.

See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab

Error: Failed to load processor bash
No macro or processor named 'bash' found

Explicit parallelism

The parallel computing toolbox is available on Cypress. You can use up to 12 workers for shared parallel operations on a single node in the current MATLAB version. Our license does not include MATLAB Distributed Computing Server. Therefore, multi-node parallel operations are not supported.

Workers are like independent processes. If you want to use 4 workers, you have to request at least 4 tasks within a node.

Error: Failed to load processor bash
No macro or processor named 'bash' found

CreateWorker.m is a Matlab code to create workers.

Error: Failed to load processor matlab
No macro or processor named 'matlab' found

Parfor.m is a sample 'parfor' test code,

Error: Failed to load processor matlab
No macro or processor named 'matlab' found

See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab

Error: Failed to load processor bash
No macro or processor named 'bash' found

Running MATLAB with Automatic Offload

Internally MATLAB uses Intel MKL Basic Linear Algebra Subroutines (BLAS) and Linear Algebra package (LAPACK) routines to perform the underlying computations when running on Intel processors.

Intel MKL includes Automatic Offload (AO) feature that enables computationally intensive Intel MKL functions to offload partial workload to attached Intel Xeon Phi coprocessors automatically and transparently.

As a result, MATLAB performance can benefit from Intel Xeon Phi coprocessors via the Intel MKL AO feature when problem sizes are large enough to amortize the cost of transferring data to the coprocessors.

In SLURM script, make sure that option --gres=mic:1 is set and intel-psxe module as well as the MATLAB module has been loaded.

Error: Failed to load processor bash
No macro or processor named 'bash' found

Note that

Error: Failed to load processor bash
No macro or processor named 'bash' found

enables Intel MKL Automatic Offload (AO).

The sample cose is below:

Error: Failed to load processor matlab
No macro or processor named 'matlab' found

See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab

Error: Failed to load processor bash
No macro or processor named 'bash' found

To generate the offload report at run time,

export OFFLOAD_REPORT=2
  • Setting OFFLOAD_REPORT to 0 (or not setting it) results in no offload report.
  • Setting OFFLOAD_REPORT to 1 results in a report including:
    • Name of function called
    • Effective Work Division
    • Time spent on Host during call
    • Time spent on each available Phi coprocessor during call
  • Setting OFFLOAD_REPORT to 2 results in a report including everything from 1, and in addition:
    • Amount of data transferred to and from each Phi during call

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.