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

조회 수: 19 (최근 30일)
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 CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by