Can I run a .NET assembly created with Compiler SDK in parallel threads in MATLAB R2023a?

6 visualizzazioni (ultimi 30 giorni)

I am using MATLAB R2023a on Windows 10. I have compiled a .NET assembly DLL file that I would like to use in a C# application. Can I run a function from this DLL file in C# in parallel threads?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 25 Lug 2024
This depends on how you are packaging your MATLAB functions into .NET assemblies.
If you are using the MWArray API, then the MATLAB Runtime (MCR) makes use of thread locking, meaning that only one thread is allowed to access the MCR at a time. This MATLAB Answers post  on "How to run multiple instances of MCR " goes into more detail about ways to parallelize .NET assemblies from the MWArray API.
If you are using the MATLAB Data API for .NET, which was introduced in R2022b, then you are able to run .NET assemblies in parallel with MATLAB runtime out-of-process mode. This is because a new thread-safe design in the MATLAB Data API facilitates concurrent data creation and consumption across multiple threads without the need for thread locking in the MCR. This is the recommended API, and has other advantages that are detailed in the .NET Assembly Integration documentation.
The downside of using out-of-process is that data needs to be marshalled between the C#/.NET process and the MATLAB runtime process. If a large amount of data needs to be passed. It will have negative impact on the performance.

Più risposte (0)

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by