-->

How do multiple calls on a single threaded DLL fun

2019-08-04 19:10发布

问题:

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).