Speed up Matlab Xin Sheng Zhou Matlab MATrix LABoratory Started - - PowerPoint PPT Presentation

speed up matlab
SMART_READER_LITE
LIVE PREVIEW

Speed up Matlab Xin Sheng Zhou Matlab MATrix LABoratory Started - - PowerPoint PPT Presentation

Speed up Matlab Xin Sheng Zhou Matlab MATrix LABoratory Started in the late 1970s Matrix manipulation Plotting of data Implementation of algorithms Creation of user interface Interfacing with other languages, such as C


slide-1
SLIDE 1

Speed up Matlab

Xin Sheng Zhou

slide-2
SLIDE 2

Matlab

 MATrix LABoratory

 Started in the late 1970s  Matrix manipulation  Plotting of data  Implementation of algorithms  Creation of user interface  Interfacing with other languages, such as C and

Fortran

 Slower, but reducing programming effort

slide-3
SLIDE 3

Java

 Java based

 Appeared in 1995  Run on Java Virtual

Machine

 Compile once, run

everywhere

 Inherited slower than

C/C++

 Currently (February 2012),

microbenchmarks show Java 7 is approximately 1.5 times slower than C

slide-4
SLIDE 4

Code 1

slide-5
SLIDE 5

Preallocating arrays

slide-6
SLIDE 6

Preallocating arrays

 Looking for larger memory  Moving data

slide-7
SLIDE 7

Preallocating arrays

 Looking for larger memory  Moving data

slide-8
SLIDE 8

Preallocating arrays

slide-9
SLIDE 9

Preallocating a non-double matrix

 A = int8(zeros(100));  A = zeros(100, 'int8');

slide-10
SLIDE 10

Changing a variable’s data type or dimension

 Another case: assigning real and complex

numbers

slide-11
SLIDE 11

Using appropriate logical operators

 Large if…else… block, consider

switch…case…

slide-12
SLIDE 12

Code 2

slide-13
SLIDE 13

Vectorizing loops

slide-14
SLIDE 14

Profiling

 Measure where a program spends time

slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18

Case study

 Low density parity check decoder

Block decoding Block length: 106 Generate parity check matrix Decoding

slide-19
SLIDE 19

Resource used for block length 10^6 and 10^7

slide-20
SLIDE 20

LDPC Code

 H*cT=0  For code ½, block length 106

 H: Matrix (0.5*106,106)  C: Row vector, size 106

 Encoding: c=s*G

 s: row vector, size 0.5*106  G: matrix, (0.5*106,106)  Get G from H is not easy  Instead, generate parity check bits p=A-1Bs

 H=[A B], c=[p s]

 Matlab’s matrix multiplication and inversion cannot be used since it is

based on double value and encoding is based on GF(2)

 Solution: Custom matrix inversion and multiplication on GF(2)  Inversion is slow, and A-1 is required to be saved  When block length > 105, saving is also slow  Since H is sparse, sparse matrix format should be used. However, A-1 is

not sparse

slide-21
SLIDE 21
slide-22
SLIDE 22
slide-23
SLIDE 23

Other ways…

 Parallel computing

Multi-threaded GPU Multi-machine

 MEX file  Matlab Compiler

slide-24
SLIDE 24

Summary

 Preallocating arrays  Vectorizing loops  Profiling

slide-25
SLIDE 25

Read more …