Can I run a .NET assembly created with Compiler SDK in parallel threads in MATLAB R2023a?
6 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2024-7-25
回答: MathWorks Support Team
2024-7-31
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?
采纳的回答
MathWorks Support Team
2024-7-25
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.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!