Embedded Systems Design Europe - February 2008 - (Page 32) feature Accelerating MATLAB using MEX-files BY LUC SEMERIA ATLAB is great tool for algorithm development. It provides a simple programming environment with an extensive library of functions to help develop, analyze and visualize complex algorithms. However, MATLAB is sometimes slow, which limits its usefulness. This article gives a quick overview of the different techniques available for speeding up MATLAB code. It covers the basics of performance profiling, vectorization, and turning MATLAB code into compiled MEX-files. What slows MATLAB down? MATLAB is an interpreted language. This means each operation carries an additional overhead not found in compiled languages such as C or C++. (Note: MATLAB includes just-in-time (JIT) machine code creation which alleviates this problem in limited instances). For every single operation in MATLAB, the interpreter has to look at the operands involved and select the correct computation to perform. This selection is based on the base data types (double real, complex, char, logical, etc.) and shapes (scalar, row, column, matrix, etc.) of the operands. Once the operations are completed, the resulting values need to be stored. For every single assignment, the MATLAB interpreter has to look at both input and output operands and decide if more memory needs to be allocated or if values need to be converted in the assignment. This selection and assignment overhead is the main reason MATLAB is slower than compiled languages. The interpreter overhead is especially significant when your operations are performed on scalars or small sets of data. This helps explain why scalar-based loops are notoriously slow in MATLAB. The typical rule for accelerating code is to optimize where it matters. If your spend 80 percent of your run-time on 20 lines of code or in one function, then this is where you want to focus your effort. The MATLAB Profiler tool that is built into MATLAB is a great way to find performance bottlenecks in your code. This easy-to-use tool can be called from the command line using the profile command or from the MATLAB desktop using Desktop > Profiler. For a given run, the profiler viewer allows you to navigate between functions and browse through the code, allowing you to quickly find where M 32 JANUARY – FEBRUARY 2008 | embedded systems design europe | www.embedded.com/europe 032-033-034_ESDE.indd 32 6/02/08 16:53:11 http://www.embedded.com/europe
Table of Contents Feed for the Digital Edition of Embedded Systems Design Europe - February 2008 Embedded Systems Design Europe - February 2008 Contents ARTEMIS and ENIAC Get Parlimentary Approval Product Teardown Videos Come On Screen Esterel and Abslnt Integrate Products Microsoft Opens Windows to Networked Embedded Applications Trango Embeds Virtualization Tool in Cavium's Multicore CPUs MindTree - ADI Develop Security DVR Platform NXP Extends Deal with ARM to Cover MCUs Automotive and Embedded to Dominate DATE 08 ZigBee Spec Gets Smart On Energy Updated Card Spec Provides for Power-On Boot The Basics of Embedded Multitasking On a PIC Cover Feature: The Art of FPGA Construction Is Symmetric Multiprocessing For You? Accelerating MATLAB Using MEX-Files ARM Provides the Microcontroller Solution Embedded World Advertising Contracts Embedded Systems Design Europe - February 2008 Embedded Systems Design Europe - February 2008 - Embedded Systems Design Europe - February 2008 (Page Cover1) Embedded Systems Design Europe - February 2008 - Embedded Systems Design Europe - February 2008 (Page Cover2) Embedded Systems Design Europe - February 2008 - Contents (Page 3) Embedded Systems Design Europe - February 2008 - Contents (Page 4) Embedded Systems Design Europe - February 2008 - Contents (Page 5) Embedded Systems Design Europe - February 2008 - Esterel and Abslnt Integrate Products (Page 6) Embedded Systems Design Europe - February 2008 - Esterel and Abslnt Integrate Products (Page 7) Embedded Systems Design Europe - February 2008 - Microsoft Opens Windows to Networked Embedded Applications (Page 8) Embedded Systems Design Europe - February 2008 - Microsoft Opens Windows to Networked Embedded Applications (Page 9) Embedded Systems Design Europe - February 2008 - NXP Extends Deal with ARM to Cover MCUs (Page 10) Embedded Systems Design Europe - February 2008 - NXP Extends Deal with ARM to Cover MCUs (Page 11) Embedded Systems Design Europe - February 2008 - Updated Card Spec Provides for Power-On Boot (Page 12) Embedded Systems Design Europe - February 2008 - The Basics of Embedded Multitasking On a PIC (Page 13) Embedded Systems Design Europe - February 2008 - The Basics of Embedded Multitasking On a PIC (Page 14) Embedded Systems Design Europe - February 2008 - The Basics of Embedded Multitasking On a PIC (Page 15) Embedded Systems Design Europe - February 2008 - The Basics of Embedded Multitasking On a PIC (Page 16) Embedded Systems Design Europe - February 2008 - The Basics of Embedded Multitasking On a PIC (Page 17) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 18) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 19) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 20) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 21) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 22) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 23) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 24) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 25) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 26) Embedded Systems Design Europe - February 2008 - Cover Feature: The Art of FPGA Construction (Page 27) Embedded Systems Design Europe - February 2008 - Is Symmetric Multiprocessing For You? (Page 28) Embedded Systems Design Europe - February 2008 - Is Symmetric Multiprocessing For You? (Page 29) Embedded Systems Design Europe - February 2008 - Is Symmetric Multiprocessing For You? (Page 30) Embedded Systems Design Europe - February 2008 - Is Symmetric Multiprocessing For You? (Page 31) Embedded Systems Design Europe - February 2008 - Accelerating MATLAB Using MEX-Files (Page 32) Embedded Systems Design Europe - February 2008 - Accelerating MATLAB Using MEX-Files (Page 33) Embedded Systems Design Europe - February 2008 - Accelerating MATLAB Using MEX-Files (Page 34) Embedded Systems Design Europe - February 2008 - ARM Provides the Microcontroller Solution (Page 35) Embedded Systems Design Europe - February 2008 - ARM Provides the Microcontroller Solution (Page 36) Embedded Systems Design Europe - February 2008 - ARM Provides the Microcontroller Solution (Page 37) Embedded Systems Design Europe - February 2008 - Embedded World (Page 38) Embedded Systems Design Europe - February 2008 - Embedded World (Page 39) Embedded Systems Design Europe - February 2008 - Embedded World (Page 40) Embedded Systems Design Europe - February 2008 - Embedded World (Page 41) Embedded Systems Design Europe - February 2008 - Embedded World (Page 42) Embedded Systems Design Europe - February 2008 - Advertising Contracts (Page 43) Embedded Systems Design Europe - February 2008 - Advertising Contracts (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.