some questions about matlab coder

Hi
I am doing my senior project on 5G simulations in matlab. We are doing the QAM using precoder and some modulation functions. We want to convert the code we have into C or C++. We used the matlabe code gen and we converted to C. We were surprised by how slow the C code is compared to matlab. It takes 260 sec for C to run one trial while only 90 sec on matlab. One of the thing we did is set the code gen to use dynamic allocation instead of static. I am looking for some recommendation or suggestions on how to produce a fast enough C code. Is that possible or we have to write the code fro scratch. Thanks

3 件のコメント

Walter Roberson
Walter Roberson 2018 年 4 月 25 日
Generally speaking:
  • fixed point code can take longer than floating point (but fixed point can be used on devices that have no floating point unit)
  • code that does calculations on sufficiently large arrays often ends up calling multithreaded high-performance libraries that use all of the cores. Generated C/C++ code does not call those libraries and so operates single-core. You can use https://www.mathworks.com/help/matlab/ref/maxnumcompthreads.html to test to see if this is the reason the generated code is slower (that is, by restricting your MATLAB to one thread.)
Ryan Livingston
Ryan Livingston 2018 年 4 月 27 日
編集済み: Ryan Livingston 2018 年 4 月 27 日
MATLAB Coder added the ability for the generated code to call LAPACK in R2016a:
and FFTW in R2017b:
Using these will give you optimized linear algebra and FFT routines respectively.
Walter Roberson
Walter Roberson 2018 年 4 月 27 日
Thanks for the update, Ryan.

サインインしてコメントする。

回答 (3 件)

Ji Lee
Ji Lee 2018 年 4 月 25 日

2 投票

Reducing the usage of dynamic memory allocation is one of the general optimization strategies one can start with when trying to improve the performance of generated code. We do have a useful documentation section that describes various optimizations and patterns. I've linked it below. Included in the first several topics linked from this section is a discussion on variable sizing and dynamic memory allocations.
matlabcoder
matlabcoder 2018 年 4 月 30 日

0 投票

Thank you all for the information, but I wonder why Mathworks doesn't push updates to include the features mentioned in Ryan comment.
matlabcoder
matlabcoder 2018 年 5 月 1 日

0 投票

The question is, is it possible to get the C code to run faster than the Matlab code, or it is possible that we have to write the whole code in C from scratch.

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

製品

タグ

質問済み:

2018 年 4 月 24 日

回答済み:

2018 年 5 月 1 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by