Can Compiler SDK C++ library support multithread?

8 views (last 30 days)

I use MATLAB Compiler SDK to compile a MATLAB function, and this function will be called in an app with concurrent users. Can this be supported?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Apr 2025
When using the C++ MATLAB Data API, you can either start the run-time in in-process mode or out-of-process mode:
When running in in-process mode, there is only a single interpreter thread and thus all calls to your library will be serialized. In this case, there will be no concurrency benefit.
When running in out-of-process-mode, there will be a separate mvm server for each library object created. Thus, if you call 'initMATLABLibrary' from each thread, each thread would have its own interpreter, and hence the threads will able to run MATLAB code concurrently. However, since the MATLAB Runtime is out-of-process, there is a trade-off in that your program must communicate data in-between processes. Overall, whether there is a performance boost in this case is dependent on how much data your application must transfer between the run-time process relative to how much work is done in the library code.
Also, the out-of-process feature has not been heavily used and therefore is not as stable as in-process.
The out-of-process mode is not supported with mwArray API. Namely it doesn't support multithread.

More Answers (0)

Categories

Find more on Get Started with MATLAB Compiler SDK in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!