# Matlab

### From CVL Wiki

(→How to use Matlab on CVL) |
|||

(84 intermediate revisions by 6 users not shown) | |||

Line 1: | Line 1: | ||

− | |||

− | |||

− | |||

− | |||

+ | [[Image:Matlab.jpg|right]] | ||

+ | =How to use Matlab on CVL= | ||

+ | '''[[Using the CVL|Log in]]''' to the CVL Workstations. | ||

+ | <br><br>Type the following command | ||

+ | matlab | ||

− | + | =General Information about Matlab= | |

+ | MatLab is a program developed by MathWorks Incorporated. This program provides a high-level language and interactive environment that enables | ||

+ | you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and Fortran. | ||

− | + | '''The "Toolboxes" that the Virginia Tech license offers are:''' | |

− | + | *Simulink | |

+ | *Aerospace Blockset | ||

+ | *Aerospace Toolbox | ||

+ | *Bioinformatics Toolbox | ||

+ | *Communications System Toolbox | ||

+ | *Computer Vision System Toolbox | ||

+ | *Control System Toolbox | ||

+ | *Curve Fitting Toolbox | ||

+ | *DSP System Toolbox | ||

+ | *Data Acquisition Toolbox | ||

+ | *Database Toolbox | ||

+ | *Embedded Coder | ||

+ | *Fixed-Point Toolbox | ||

+ | *Fuzzy Logic Toolbox | ||

+ | *Global Optimization Toolbox | ||

+ | *HDL Coder | ||

+ | *Image Acquisition Toolbox | ||

+ | *Image Processing Toolbox | ||

+ | *Instrument Control Toolbox | ||

+ | *LMI Control Toolbox (Transitioned) | ||

+ | *MATLAB Builder NE | ||

+ | *MATLAB Coder | ||

+ | *MATLAB Compiler | ||

+ | *MATLAB® C/C++ Math Library (Transitioned) | ||

+ | *Mapping Toolbox | ||

+ | *Mu-Analysis and Synthesis Toolbox (Transitioned) | ||

+ | *Neural Network Toolbox | ||

+ | *Optimization Toolbox | ||

+ | *Parallel Computing Toolbox | ||

+ | *Partial Differential Equation Toolbox | ||

+ | *Robust Control Toolbox | ||

+ | *Signal Processing Toolbox | ||

+ | *SimBiology | ||

+ | *SimElectronics | ||

+ | *SimEvents | ||

+ | *SimMechanics | ||

+ | *SimPowerSystems | ||

+ | *Simscape | ||

+ | *Simulink 3D Animation | ||

+ | *Simulink Coder | ||

+ | *Simulink Control Design | ||

+ | *Simulink Fixed Point | ||

+ | *Spline Toolbox (Transitioned) | ||

+ | *Spreadsheet Link EX | ||

+ | *Stateflow | ||

+ | *Stateflow Coder (Transitioned) | ||

+ | *Statistics Toolbox | ||

+ | *Symbolic Math Toolbox | ||

+ | *System Identification Toolbox | ||

+ | *Wavelet Toolbox | ||

+ | *xPC Target | ||

+ | '''Toolboxes that have been integrated with other Toolboxes:''' | ||

+ | <br>The Robust Control Toolbox has merged with the following toolboxes | ||

+ | * Mu-Analysis and Synthesis | ||

+ | * LMI Control | ||

+ | =Installing Matlab= | ||

+ | Email support@ece.vt.edu for installation directions. | ||

+ | ==Installing Matlab on Linux/UNIX== | ||

+ | *This Section is under construction. | ||

+ | ==Installing Matlab on MAC OSX== | ||

− | == | + | ==Using the MPI parallel toolbox== |

− | [ | + | The CVL lab has installed a toolbox that simplifies parallelizing matlab code. This is the location of the [http://einar.heiberg.se/mpi/index.html Matlab Parallelization Toolkit]. It utilizes a Master/Slave arrangement to automatically login to multiple machines and have them individually run parts of a matlab script. The majority of the setup and configuration has been done on all of the CVL machines, but it is not in your matlab path by default. |

− | + | ||

− | + | ||

+ | *In order to access the MPI toolbox, you must manually add the directory '/software/MPI' to your path, either with the matlab path GUI, or with the command | ||

+ | addpath /software/MPI | ||

+ | *Once this is done, more information on how to operate the toolkit can be obtained by typing | ||

+ | help MPI from the matlab command window. | ||

− | + | *The [http://computing.ece.vt.edu/MPI/example2.m following] is an example of how to implement the toolbox in matlab code | |

− | ==Additional Links | + | %This part defines how many nodes to try to use |

+ | %connects to available machines, and fires a Matlab slave node | ||

+ | addpath /software/MPI | ||

+ | %addpath /software/MPI_VAL32 | ||

+ | |||

+ | %Read the config file set up for the cluster | ||

+ | mconfig = pconfig; | ||

+ | %Use all the machines available | ||

+ | Nparallel = length(mconfig); | ||

+ | %Run this many MATLAB processes per machine. This should be set to 1 to | ||

+ | %make resources available for others. | ||

+ | Nperhost = 1; | ||

+ | |||

+ | %Fire up matlab on the slaves. It may be worth using the load-checking | ||

+ | %version of psetup('available', Nparallel*Nperhost); | ||

+ | for j=1:Nparallel | ||

+ | psetup(mconfig{j}{1}, Nperhost); | ||

+ | end | ||

+ | |||

+ | |||

+ | %A example of a data set to chew on | ||

+ | a = rand(64, 64, 32); | ||

+ | res = zeros(size(a)); | ||

+ | |||

+ | %Run a parallel profiler on the code to be run to see how much speedup there was (optional) | ||

+ | pprofile on -detail builtin | ||

+ | |||

+ | %The main parallel loop. | ||

+ | %It executes the function 'exampleloop.m' | ||

+ | pfor(1:size(a, 3), 'res(:, :, %d) = exampleloop(a(:, :, %d));'); | ||

+ | |||

+ | %Finish the parallel profile stats collection | ||

+ | s = pprofile('report'); | ||

+ | |||

+ | |||

+ | %Once the main computation is done, shut-down all the slave Matlab nodes | ||

+ | MPI_Finalize; | ||

+ | |||

+ | [http://computing.ece.vt.edu/MPI/exampleloop.m Here's] a functional example of an 'exampleloop.m' matlab function | ||

+ | function out = exampleloop(in) | ||

+ | |||

+ | tempout = in | ||

+ | N=10000; | ||

+ | for i=1:N | ||

+ | tempout = inv(tempout) + rand(size(tempout)); | ||

+ | end | ||

+ | out = tempout | ||

+ | |||

+ | |||

+ | One important point to note is that a portion of the MPI toolbox library must be compiled for the platform it's being run on. This has already been done for most of the CVL machines being run as 64-bit Linux. If the toolbox is to be used on a 32-bit Linux installation, a the [http://computing.ece.vt.edu/MPI/MPI121_CVL.tar.gz MPI library] will have to be installed into your home directory (or somehwere else you have write permission). It will also have to be added to your matlab path, and | ||

+ | makeMPI | ||

+ | must be issued from the matlab command prompt. The matlab installation must include mex, mcc, gcc, and g++ compiler properly installed. | ||

+ | |||

+ | |||

+ | ==Help== | ||

+ | |||

+ | For any additional questions, comments, or concerns contact your system administrator or post a ticket on [https://helpdesk.ece.vt.edu/helpdesk/index.php Help Desk]. | ||

+ | |||

+ | =Additional Links= | ||

[http://www.mathworks.com/ Mathworks home page] | [http://www.mathworks.com/ Mathworks home page] |

## Latest revision as of 10:42, 3 December 2015

## Contents |

# [edit] How to use Matlab on CVL

**Log in** to the CVL Workstations.

Type the following command

matlab

# [edit] General Information about Matlab

MatLab is a program developed by MathWorks Incorporated. This program provides a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and Fortran.

**The "Toolboxes" that the Virginia Tech license offers are:**

- Simulink
- Aerospace Blockset
- Aerospace Toolbox
- Bioinformatics Toolbox
- Communications System Toolbox
- Computer Vision System Toolbox
- Control System Toolbox
- Curve Fitting Toolbox
- DSP System Toolbox
- Data Acquisition Toolbox
- Database Toolbox
- Embedded Coder
- Fixed-Point Toolbox
- Fuzzy Logic Toolbox
- Global Optimization Toolbox
- HDL Coder
- Image Acquisition Toolbox
- Image Processing Toolbox
- Instrument Control Toolbox
- LMI Control Toolbox (Transitioned)
- MATLAB Builder NE
- MATLAB Coder
- MATLAB Compiler
- MATLAB® C/C++ Math Library (Transitioned)
- Mapping Toolbox
- Mu-Analysis and Synthesis Toolbox (Transitioned)
- Neural Network Toolbox
- Optimization Toolbox
- Parallel Computing Toolbox
- Partial Differential Equation Toolbox
- Robust Control Toolbox
- Signal Processing Toolbox
- SimBiology
- SimElectronics
- SimEvents
- SimMechanics
- SimPowerSystems
- Simscape
- Simulink 3D Animation
- Simulink Coder
- Simulink Control Design
- Simulink Fixed Point
- Spline Toolbox (Transitioned)
- Spreadsheet Link EX
- Stateflow
- Stateflow Coder (Transitioned)
- Statistics Toolbox
- Symbolic Math Toolbox
- System Identification Toolbox
- Wavelet Toolbox
- xPC Target

**Toolboxes that have been integrated with other Toolboxes:**

The Robust Control Toolbox has merged with the following toolboxes

- Mu-Analysis and Synthesis
- LMI Control

# [edit] Installing Matlab

Email support@ece.vt.edu for installation directions.

## [edit] Installing Matlab on Linux/UNIX

- This Section is under construction.

## [edit] Installing Matlab on MAC OSX

## [edit] Using the MPI parallel toolbox

The CVL lab has installed a toolbox that simplifies parallelizing matlab code. This is the location of the Matlab Parallelization Toolkit. It utilizes a Master/Slave arrangement to automatically login to multiple machines and have them individually run parts of a matlab script. The majority of the setup and configuration has been done on all of the CVL machines, but it is not in your matlab path by default.

- In order to access the MPI toolbox, you must manually add the directory '/software/MPI' to your path, either with the matlab path GUI, or with the command

addpath /software/MPI

- Once this is done, more information on how to operate the toolkit can be obtained by typing

help MPI from the matlab command window.

- The following is an example of how to implement the toolbox in matlab code

%This part defines how many nodes to try to use %connects to available machines, and fires a Matlab slave node addpath /software/MPI %addpath /software/MPI_VAL32 %Read the config file set up for the cluster mconfig = pconfig; %Use all the machines available Nparallel = length(mconfig); %Run this many MATLAB processes per machine. This should be set to 1 to %make resources available for others. Nperhost = 1; %Fire up matlab on the slaves. It may be worth using the load-checking %version of psetup('available', Nparallel*Nperhost); for j=1:Nparallel psetup(mconfig{j}{1}, Nperhost); end %A example of a data set to chew on a = rand(64, 64, 32); res = zeros(size(a)); %Run a parallel profiler on the code to be run to see how much speedup there was (optional) pprofile on -detail builtin %The main parallel loop. %It executes the function 'exampleloop.m' pfor(1:size(a, 3), 'res(:, :, %d) = exampleloop(a(:, :, %d));'); %Finish the parallel profile stats collection s = pprofile('report'); %Once the main computation is done, shut-down all the slave Matlab nodes MPI_Finalize;

Here's a functional example of an 'exampleloop.m' matlab function

function out = exampleloop(in) tempout = in N=10000; for i=1:N tempout = inv(tempout) + rand(size(tempout)); end out = tempout

One important point to note is that a portion of the MPI toolbox library must be compiled for the platform it's being run on. This has already been done for most of the CVL machines being run as 64-bit Linux. If the toolbox is to be used on a 32-bit Linux installation, a the MPI library will have to be installed into your home directory (or somehwere else you have write permission). It will also have to be added to your matlab path, and

makeMPI

must be issued from the matlab command prompt. The matlab installation must include mex, mcc, gcc, and g++ compiler properly installed.

## [edit] Help

For any additional questions, comments, or concerns contact your system administrator or post a ticket on Help Desk.

# [edit] Additional Links

Mathworks home page

Matlab Tutorials

Additional information about Matlab

Octave A Free alternative to Matlab