Why can't I run Simulink from the command line inside a parfor loop?

1 view (last 30 days)
I have some code that creates and runs multiple Simulink models in normal mode from the command line like this:
matlabpool open 4;
parfor i = 1:100
sys = sprintf('system_%d', i);
new_system(sys);
%define the system
results(i, 1:1000) = sim(sys, [0 1000]);
close_system('foo', 0);
end
It seems straightforward and it does in fact run fine for a while using all four cores. However, within a minute or so, I invariably get the message:
The client lost connection to lab 2.
This might be due to network problems, or the interactive matlabpool job might have errored. This is causing: java.io.IOException: An existing connection was forcibly closed by the remote host
and it continues running as if it was a regular for loop instead of a parfor loop, using only one core. What's wrong? I know there are unique issues related to calling sim from within parfor, but as far as I know they all have to do with running the same model in parallel, not creating and running different models in parallel as in in my code. Thanks for any help~
  1 Comment
Rick Rosson
Rick Rosson on 26 Aug 2011
Which release of MATLAB are you using?
Have you tried this code from a MATLAB script, or only directly from the command line?
Have you tried creating a MATLAB function that calls the 'sim' command, and then calling that function from within the 'parfor' loop?

Sign in to comment.

Answers (2)

Lucas García
Lucas García on 26 Aug 2011
Are you running MATLAB in a 32-bit or 64-bit machine? I say this because if you are running MATLAB in 32-bit and you are passing a lot of data to your workers at each iteration, memory transfer is limited to ~600MB. In 64-bit it's around ~2GB:
Maybe try a simpler problem to see if it works.

Andy Yancy
Andy Yancy on 26 Aug 2011
Thanks for the responses. To answer both: this is release 2010a running on a quad core Win32 machine (Windows Server 2003). The amount of data involved is orders of magnitude less than 600 MB. I have tried it from a script and I have tried putting the guts of the parfor loop inside a function and then calling the function from the parfor loop. The same thing happens every time.
Now that I've been wrestling with it for a while, I'm almost certain that there is some sort of Simulink memory leak or other bug related to file i/o that only crops up when large numbers of simulations are run in parallel, as if file handles are not getting closed somewhere deep in the Simulink engine. Is anything like that known or suspected by anyone else?
Well, thanks again for any help~

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!