C++ code generated by Matlab coder too slow
Ältere Kommentare anzeigen
Hello,
I have an algorithm written in matlab, which detects some artefatcs in blood pulsewave. These algorithm is converted to C++ by maltab coder and I use these C++ files in my C# SW. It works fine.
But, I use several FIRs in my code, one of them is 10000 order FIR. The signal length is around 1M samples, so it take too much time to count it with filter(...) function or conv(..) function. I have tried to count the FIR with convolution theorem, I have used this:
fftLen = 2^nextpow2(length(values));
filteredValues = ifft(fft(values,fftLen).*fft(coefs,fftLen));
It works more then 30x faster in matlab. But if I convert the code to C++ by matlab Coder, it is not so fast. It is more then 10x slower than the matlab version. I use matlab 2017b. Why?
5 Kommentare
Adam
am 12 Feb. 2019
A lot of builtin code is well optimised in Matlab and utilises multi-threading. As far as I am aware C code created through code will not use multithreading and may lose many of the optimisations that are achieved by the Matlab code. I have no idea how Matlab coder works to turn Matlab code into C code, but it is not perfect. Sometimes it will create suboptimal C code.
Josef Shrbeny
am 12 Feb. 2019
Bearbeitet: Josef Shrbeny
am 12 Feb. 2019
Walter Roberson
am 12 Feb. 2019
MATLAB detects some patterns of code, and if it finds that the arrays are "large enough" to make it worth while, automatically invokes BLAS or LAPACK libraries to do the work. Those libraries are multi-threaded even without the Parallel Computing toolbox.
Preethi
am 13 Feb. 2019
Hi Walter,
BLAS and LAPACK are applicable from which version of MATLAB
Walter Roberson
am 13 Feb. 2019
Multithreaded was added in R2007a according to Loren's blog of March 1, 2007.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Algorithm Design Basics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!