speed up matlab
play

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


  1. Speed up Matlab Xin Sheng Zhou

  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

  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

  4. Code 1

  5. Preallocating arrays

  6. Preallocating arrays  Looking for larger memory  Moving data

  7. Preallocating arrays  Looking for larger memory  Moving data

  8. Preallocating arrays

  9. Preallocating a non-double matrix  A = int8(zeros(100));  A = zeros(100, 'int8');

  10. Changing a variable’s data type or dimension  Another case: assigning real and complex numbers

  11. Using appropriate logical operators  Large if…else… block, consider switch…case…

  12. Code 2

  13. Vectorizing loops

  14. Profiling  Measure where a program spends time

  15. Case study  Low density parity check decoder  Block decoding  Block length: 10 6  Generate parity check matrix  Decoding

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

  17. LDPC Code  H*c T =0  For code ½, block length 10 6  H: Matrix (0.5*10 6 ,10 6 )  C: Row vector, size 10 6  Encoding: c=s*G  s: row vector, size 0.5*10 6  G: matrix, (0.5*10 6 ,10 6 )  Get G from H is not easy  Instead, generate parity check bits p=A -1 Bs  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 > 10 5 , saving is also slow  Since H is sparse, sparse matrix format should be used. However, A -1 is not sparse

  18. Other ways…  Parallel computing  Multi-threaded  GPU  Multi-machine  MEX file  Matlab Compiler

  19. Summary  Preallocating arrays  Vectorizing loops  Profiling

  20. Read more …

Recommend


More recommend