简体   繁体   中英

Convert MATLAB to C++ using MATLAB coder

我打算将“矩阵上的全部操作”的MATLAB代码转换为C ++,我不确定MATLAB编码器是否会生成高效的C ++代码。尽管如此,还是要手动转换它,这样更好吗?

As others have said, generating the code with MATLAB Coder, compiling it with your compiler's optimizations on, and measuring is the only way to know if your needs will be met.

MATLAB Coder generates the code directly for most algorithms without using external libraries. In certain cases libraries may be used or may be requested by the user. Of particular interest for you may be BLAS and LAPACK integration.

If you are doing linear algebra as part of your matrix operations, then consider configuring MATLAB Coder to call high-performance BLAS and LAPACK libraries of your choosing:

https://www.mathworks.com/help/coder/ug/speed-up-matrix-operations-in-generated-standalone-code-by-using-blas-calls.html

https://www.mathworks.com/help/coder/ug/generate-code-that-calls-lapack-functions.html

That will cause MATLAB Coder to replace its algorithms with calls to the libraries you specify for linear algebra operations like *, \\, linsolve, lu, svd, eig , etc.

MATLAB Coder provides suggestions for improving the performance of the generated code:

https://www.mathworks.com/help/coder/optimize-speed-of-generated-code.html

One possible approach in cases like this is to generate the code and profile it with a profiler like prof, VTune, AMD Codeanalyst, the Visual Studio performance tools, etc. If you find a few expensive kernels where the generated code may not meet your performance needs, hand write replacements for those parts with a C-like interface and integrate them with your generated code using coder.ceval .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM