2

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?

Amro
  • 123,847
  • 25
  • 243
  • 454
  • The question is a bit unclear, are you using a DLL library that calls into MATLAB or are you using an external library from within MATLAB (like a MEX-function linked against the DLL)? If it's the former how is it communicating with MATLAB (MATLAB Engine or was it compiled using the MATLAB Compiler, etc..)? – Amro Sep 19 '14 at 18:09
  • I actually had someone else put the assembly together, but to the best of my knowledge it's a "DLL library that calls into MATLAB" communicating through the MATLAB Engine. This is my first foray into this type of project so I'm still trying to understand the best method for handling the given problem. Most MILP calculations commonly discussed are large scale problems, where mine appears to be the less commonly discussed higher frequency variety. From what I have been able to gather there appears to be a need to possibly implement parallelism. I'm just not sure the best method of implementation – user3033725 Sep 20 '14 at 18:59
  • Can the parallelism to be implemented within the DLL or is there a better way? Is the MATLAB Engine capable of scaling for parallelism or do I need a compiled version of the calculation that can have copies opened across multiple threads? – user3033725 Sep 20 '14 at 19:04
  • Let me link to some related questions: [Thread safety of Matlab engine API](http://stackoverflow.com/q/248421/97160), [Multithreaded C++ application using Matlab Engine](http://stackoverflow.com/q/19250493/97160) – Amro Sep 20 '14 at 20:16
  • Thanks for such a thorough response. – user3033725 Sep 26 '14 at 15:43
  • I posted my previous comments as an answer :) – Amro Sep 26 '14 at 15:48

1 Answers1

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

Amro
  • 123,847
  • 25
  • 243
  • 454