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

4 visualizzazioni (ultimi 30 giorni)
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".

Risposte (1)

Jan
Jan il 24 Set 2021
Modificato: Jan il 24 Set 2021
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 Commenti
Jakub Jon
Jakub Jon il 24 Set 2021
I am curious, if it is possible to get fast implementation of filter in C instead of what Matlab generates normally.
Jan
Jan il 26 Set 2021
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.

Accedi per commentare.

Categorie

Scopri di più su MATLAB Coder in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by