MATLAB workshop 2011: Difference between revisions
m (added workshop demos) |
(added demos) |
||
Line 106: | Line 106: | ||
# Distributed Job | # Distributed Job | ||
# Small shell script using MATLAB | # Small shell script using MATLAB | ||
=== Serial Job === | |||
localSubmit.m | |||
<pre> </pre> | |||
primenofun.m | |||
<pre> </pre> | |||
=== Offload Serial Job to Cheaha using Submit Script== | |||
serialSubmit.m | |||
<pre></pre> | |||
=== Convert Serial Job to Parallel and run it locally === | |||
# Convert 'for' loop to a 'parfor' | |||
# Start a matlabpool using 'matlabpool open local #no_of_workers' (General rule is no_of_workers = no. of processor cores available) | |||
# Run the job | |||
<pre> </pre> | |||
=== Offload the Parallel Job to Cheaha === | |||
parSubmit.m | |||
<pre> </pre> | |||
=== Distributed Job === | |||
distribSubmit.m | |||
=== Shell Script Using MATLAB === | |||
varpass.m | |||
<pre> </pre> |
Revision as of 15:48, 16 September 2011
MATLAB (matrix laboratory) is a numerical computing environment and fourth-generation programming language. Developed by Mathworks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, and Fortran. An additional package, Simulink, adds graphical multi-domain simulation and Model-Based Design for dynamic and embedded systems.
In January 2011, UAB acquired a site license for MATLAB that allows faculty, staff, post-docs, and graduate students to use MATLAB, Simulink, and 42 toolboxes (including the parallel toolbox) for research activities on campus and personal systems. Additionally, MATLAB is available to students on campus computer systems.
Install and Configure MATLAB
Using Mathworks software available under the UAB campus license on your computer involves download and install steps common to all software packages and an authorization step that grants you the rights to use the software under the campus agreement.
Installation
Installation Overview
NOTE:These steps are common to all install scenarios and are detailed in Downloading and Installing MATLAB.
- Create an account at the Mathworks site using your campus @uab.edu email address.
- Request an activation key.
- Associate your Mathworks account with the campus-wide MATLAB license using your activation key.
- Download the software from the mathworks download site and install MATLAB. (Contact a MATLAB-TAH Asset Manager to get download rights)
- Activate the software using the activation scenario that best suits your particular needs.
Installation for Various Activation Scenarios
NOTE: Most on-campus users are encouraged to use the Simplified MATLAB Install option for activation unless there are special circumstances that require the alternative activation scenarios.
- Simplified MATLAB Install - This is the recommended install when MATLAB will be used on computers that remain connected to the campus network. This installation requires MatLab software to be installed on your computer and provides a simple 2-line file to activate the software. This option is highly recommend.
- Matlab Designated Computer Install - This option is recommended for mobile computing systems which may not have network access when MATLAB is being used. This install type authorizes an individual computer to run MATLAB, allowing MATLAB to run regardless of where the computer is located.
Configure MATLAB
Configuration Overview
Configuring the Parallel Computing Toolbox involves three steps documented below:
- install MATLAB submit functions on your workstation
- configure the "cheaha" parallel computing target to which PCT tasks can be submitted
- run the validation tests to confirm a working installation.
This page documents the DCS configuration for MATLAB 2010b and later. For DCS configuration instructions on previous versions of MATLAB, please see the page MatLab DCS R2010a and Earlier
Using MATLAB DCS requires you have a cluster account on Cheaha. Please request an account by sending an email to [[1]] and include your campus affiliation and a brief statement of your research interests for using the cluster.
MATLAB Submit Functions
The MATLAB submit functions create a cluster job context for your code and are responsible for transferring your code and the data it analyzes to the cluster for processing.
These submit functions must be installed on your computer and must be accessible to MATLAB via the MATLAB PATH environment. The easiest way to accomplish this is to copy the submit functions to the default directory created for by MATLAB. These directories on the respective operating systems are listed below.
- Download the MATLAB submit functions
- Submit Functions for MATLAB R2010b and later -(updated 02/21/2011)
- Unzip the files to a directory included in your MATLAB PATH setting. Recommended locations are:
- Windows:
My Documents\MATLAB
- Linux:
$HOME/Documents/MATLAB
- Mac:
$HOME/Documents/MATLAB
- Windows:
Once the submit function files have been downloaded and unzipped in the above paths, restart MATLAB to ensure they are properly loaded in your environment.
Parallel Computing Toolbox Configuration
The Parallel Computing Toolbox (PCT) enables language extensions in MATLAB that support dividing your application into tasks that can be executed in parallel. By default, all of these tasks will run on your local workstation using the pre-defined "local" PCT configuration.
To run these tasks on the Cheaha compute cluster, a new configuration for the PCT must be defined. In this section we will create the "cheaha" configuration and run a quick validation test to confirm its operation.
Prior to continuing, make sure you:
- can establish an SSH connection to Cheaha
- have followed the steps in the previous section
Create the "cheaha" PCT Configuration
- Download and save the Cheaha cluster configuration file in a file named "cheaha.mat".
- Start MATLAB on your workstation
- Click the "Parallel" menu
- Click "Manage Configurations"
- In the "Configurations Manager" window, click "File -> Import"
- Browse to the location where you saved the cheaha.mat file, select it, and click "Open"
The Configuration Manager should now list a new entry named "cheaha" as shown in the following image:
Personalize the "cheaha" PCT Configuration
- Double click on cheaha in the Configuration Manager window to open the configuration editor. (Note: stretch the "Generic Scheduler Configuration Properties" window to the right so that you can view all of the text in the fields making it easier to read and edit correctly.)
- Edit the following fields to use your personal data directories
- ClusterMatlabRoot: Make sure that the Root directory of MATLAB installation for workers matches the exact version of MATLAB you are using on your workstation. In this example /share/apps/mathworks/R2011a matches a MATLAB R2011a workstation install. Change the "R2011a" to match your workstation MATLAB install.
- DataLocation : Change the directory path where job data is stored to an existing directory on your workstation. For example, on Windows the directory C:\Users\<USERNAME>\Documents\MATLAB is created by default by MATLAB. Please confirm this directory is valid.
- ParallelSubmitFcn: Change the text "YOURUSERID" to your login id on Cheaha
- SubmitFcn : Change the text "YOURUSERID" to your login id on Cheaha
- Click 'OK'to save the configuration
The initial configuration will look similar to this screen shot. You will need to edit the fields as describe in the preceding steps before you can use the configuration. NOTE: be sure to replace the template user name settings "YOURUSERNAME" with the appropriate settings for your desktop and cluster account.
Validate the "cheaha" PCT Configuration
- Select Cheaha on the configuration manager page and click 'Start Validation'
- Wait for the validation to complete. This might take a few minutes and you ask for User credentials on Cheaha. All tests other than 'Matlabpool' validate on the Cheaha and the output is as shown.
Validation must pass the first three stages to use MATLAB on Cheaha.
Workshop Demo's
- Serial job
- Offload the serial job to Cheaha
- Convert serial job to parallel and run it locally
- Offload the parallel job to Cheaha
- Distributed Job
- Small shell script using MATLAB
Serial Job
localSubmit.m
primenofun.m
= Offload Serial Job to Cheaha using Submit Script
serialSubmit.m
Convert Serial Job to Parallel and run it locally
- Convert 'for' loop to a 'parfor'
- Start a matlabpool using 'matlabpool open local #no_of_workers' (General rule is no_of_workers = no. of processor cores available)
- Run the job
Offload the Parallel Job to Cheaha
parSubmit.m
Distributed Job
distribSubmit.m
Shell Script Using MATLAB
varpass.m