Matlab for Engineers Alistair Johnson 31st May 2012 Centre for Doctoral Training in Healthcare Innovation Institute of Biomedical Engineering Department of Engineering Science University of Oxford Supported by the RCUK Digital Economy Programme grant number EP/G036861/1
38
Embed
Matlab for Engineers Centre for Doctoral Training in ...gari/teaching/MatlabForEngineers...Matlab for Engineers Alistair Johnson 31st May 2012 Centre for Doctoral Training in Healthcare
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Matlab for Engineers
Alistair Johnson
31st May 2012
Centre for Doctoral Training in Healthcare InnovationInstitute of Biomedical EngineeringDepartment of Engineering Science
University of Oxford
Supported by the RCUK Digital Economy Programme grant number EP/G036861/1
Overview
Parallel computingLicensing○Licensing○Simple parallelisation - parfor details○Parallelization exercise○Parallel crashes, profiling, tips, and a remote demo
1.GPU computing2.MEX files
○LIBSVM example
Parallel Computing
LicensingParallel Computing Toolbox (PCT)
PCT ExerciseGraphical Processing Units
LicensingUsing MATLAB in the IBME (or on campus/after VPN) uses
the network license
LicensingMATLAB licenses are released:
After closing MATLABAfter a period of idle time elapses
Licensing
Try to release your licenses!As of 09/28/2011, we are restricted to 20 university wide
./lmutil lmstat -a -c /opt/MATLAB/R2010b/licenses/network.licMore detail in speaker notes.
LicensingTry to release your licenses!Here is an example of how this can be accomplished:
Parallel Computing
Some tasks lend themselves nicely to parallelizationThe main tradeoff to consider:
Computation Overhead vs Computation Time
Note that MATLAB already has implicit parallelization!
Parallel Computing Toolbox (PCT)
You will likely work with parfor loops as opposed to for loopsCalculations performed are identical, but how the
calculations are performed changesThe MATLAB client starts a pool of workersA general parallel script may look like this:
parfor
parfor requires all iterations be independent of order and each other
Variable assignment command line output and graphical displays (i.e. figures) will not display from workers
parfor rules:Don't use clear or evalDon't load/save data in a parfor loopDon't use break, return, global, or persistentUse feval for function handles
parfor variables
Try to make sure any large arrays are sliced, as this will reduce overhead, i.e.:
All of its first level indices are identical throughout the loopExactly one of the first level indices is the loop variable
parfor indexingExample workaround for ensuring a variable is indexed properly
________________________________________
PCT crashes
A PCT crash will give you the line, but not the workspace
This can make standard debugging annoyingUsually best to remove "par" from parfor and debug normally
Always open/close the matlabpool
Open:
Close:
onCleanup:
Parallelizing the peak detector
● We'll get a better idea of parallelization by using it in conjunction with the peak detector
● Open PCT_importfile.m and PCT_importfilecsv.m Ensure data.zip is extracted, and the data folder is in your
path
Example
PCT_peak_detector_for
PCT_peak_detector_parfor
PCT_peak_detector_parfor_saveSaves results!
Parallelizing Peak Detector
PCT_peak_detector.mRuns the peak detector on 8 separate data
measurements concatenated togetherDoesn't keep the output (not interested in it for demo
purposes)
SPMD example
SPMD example
Loading data, performed with spmd...All three variants (for, parfor, and spmd) are compared in PCT_comparison.m
Try it out (note: it assumes you have at least 4 workers available for use, change the defaults if necessary)
PCT_spmd_profiler.m
Parallelize EVERYTHING
parfor - simple, effective, and a good way to get started
spmd - complicated, but useful, allows for communication between cores
batch/task - multiple independent programs, very advanced
Further reading
As always, the MATLAB help is invaluable
Note that there are also demos available! At the MATLAB prompt:
demo 'toolbox' 'parallel computing'
Graphics Processing Unit (GPU)
GPUs can also be used for parallel processing
GPUs have much more cores (sometimes 512) but less processing power per core