MATLAB Answers

per isakson

Is it a good idea to run Matlab in the "background" as a local out-of-process COM server?

Asked by per isakson
on 14 Sep 2011


  1. The cpu has 4 cores
  2. An interactive application, which includes some long computations. The user don't want to wait.
  3. I hesitate to use the Parallel Computing Toolbox.
  4. Windows environment

It seems possible to run Matlab as a "Local Out-of-Process Server" from within Matlab. (I take for granted that Windows will run it in a different core.) So far I run this example, which displays "4".

h = actxserver('Matlab.Application');
msg = h.Execute('a = 2+2;');
a = h.GetVariable( 'a', 'base' );
disp( a )

The idea is to let the user start certain tasks and do something else in the application while the local out-of-process server works in the "background".

Now I wonder whether it is worth while to try to implement this. Which are all the problems and limitations I didn't think of?

The Matlab function, SYSTEM, might be an alternative. However, that has the overhead of starting Matlab for every task.

-------- EDIT ----------

I trippled my example:

h1 = actxserver('Matlab.Application');
h2 = actxserver('Matlab.Application');

and learned that only one server is started; h1 and h2 are handles of the same server instance. That came as a surprise to me. I guess it's fundamental to the COM-technology. The Matlab documentation doesn't say that explicitly(?)


--- Wishful thinking ---

I learned from the tech support that

    It is not possible to return control to the MATLAB 
    command window while invoking a COM method of an 
    actxserver application.

Thus, it is not possible to run jobs in the background with help of a local out-of-process Matlab server. However, there is an enhancement request.



1 Answer

Answer by Jan Simon
on 14 Sep 2011
 Accepted answer

The method is fine, if you have enough RAM to run two instances of MATLAB. Using SYSTEM allows to start more instances, which would use the cores more efficiently.

If the bottlenecks of your program are multi-threaded (e.g. MIN, MAX, FILTER, etc), all cores are occupied already and there will be no speedup.

  1 Comment

Thank you for your answer. I learned that I can only start ONE server instance. You gave me some confidence so I'll try it.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!