Built-in "filter" function works drastically faster in Matlab than in generated C code

6 ビュー (過去 30 日間)
Jakub Jon
Jakub Jon 2021 年 9 月 24 日
コメント済み: Jan 2021 年 9 月 26 日
Hello everyone.
I have an algorithm using "filter" function. We are testing generated to C version of it and the main bottleneck (around 50% of whole time) spent is C code related to processing of this "filter" call, and function inside which this call located take like 66%. But profile of this function in Matlab tells completely different story, even line in which "filter" called is not the most time consuming inside function calling it but like top 3. And function calling "filter" is just like top 10 in profiling only (like 4-5% instead of 66%). Unfortunately "filter" is built-in function of Matlab so I can't profile it "more" in Matlab to really understand the issue. What can cause such behavior?
I was trying to run matlab in single-thread mode and played with optimizations for code generation and compiler flags but it doesn't change overall picture of "bottleneck".

回答 (1 件)

Jan
Jan 2021 年 9 月 24 日
編集済み: Jan 2021 年 9 月 24 日
That filter becomes the bottleneck can have two reasons:
  1. filter is processed less efficiently in the generated C code.
  2. The efficiency of filter does not change, but the rest of the code is processed much faster.
  2 件のコメント
Jakub Jon
Jakub Jon 2021 年 9 月 24 日
I am curious, if it is possible to get fast implementation of filter in C instead of what Matlab generates normally.
Jan
Jan 2021 年 9 月 26 日
You find a slightly faster C implementation of FILTER here: https://www.mathworks.com/matlabcentral/fileexchange/32261-filterm . Currently Matlab is still faster if multithreading is used.
I've improved the code to consider cheaper computations of FIR filters. The multi-threading is not working yet, so it will take some time until I publish it.

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

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by