How do multiple calls on a single threaded DLL function scale?

柔情痞子 提交于 2019-12-13 01:22:56

问题


Currently I have a DLL that accesses a MILP calculation within MATLAB, from what I understand most MILP solvers are single threaded, and I was wondering how/if that comes into play with multiple simultaneous calls on the MILP solver. Do the calculations queue up behind each other and all process across that single thread or is there some way of spreading the load?

I am trying to understand how effectively this combination scales from a single call to 100 near simultaneous calls. Does it become constrained by the hardware or the software?


回答1:


As far as I know, the MATLAB Engine is not thread-safe. If your application is multi-threaded, you have to make sure that only one thread accesses the Engine API at all times. That's not to say that builtin MATLAB functions themselves are all single-threaded (in fact many operations in linear algebra, FFT, etc.. are internally multithreaded), I'm only talking about the Engine interface by which you communicate with MATLAB which is not thread-safe...

Of course that doesn't stop you from implementing parallelism using multi-processes. Just start multiple instances of your program each solving an independent Linear-Programming problem. This is the sort of thing that the Parallel Computing Toolbox relies upon (by running local background workers or even remote workers with the Distributed Computing Toolbox).



来源:https://stackoverflow.com/questions/25936761/how-do-multiple-calls-on-a-single-threaded-dll-function-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!