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

조회 수: 1 (최근 30일)
Andy Yancy
Andy Yancy 2011년 8월 26일
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
Rick Rosson
Rick Rosson 2011년 8월 26일
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?

댓글을 달려면 로그인하십시오.

답변 (2개)

Lucas García
Lucas García 2011년 8월 26일
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 2011년 8월 26일
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~

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by