simulink in parfor and for: different results

Hello,
I have a Simulink-Simulation. I need many evaluations with different parameters, therefore, i tried parallel computing.
The strange thing is: when i run the simulation on the matlab "workers" in a parfor loop, i get a different result compared to when i run it in a normal for-loop.
What could be the reason?
Thank you in advance, Arco Bast

3 件のコメント

Edric Ellis
Edric Ellis 2014 年 4 月 14 日
Do you have a specific example you can post so that we can try to reproduce the problem?
Arco
Arco 2014 年 5 月 3 日
編集済み: Arco 2014 年 5 月 3 日
Since my model is realy complex, I first want to give you more information - maybe this already allows to find the mistake.
My model describes a relatively large nonlinear ODE, that is very stiff, therefore, I'm using ode15s. It's main functionality is inside a Matlab-Function-Block.
So let's run the following code:
load('myParameters');
simOutput=cell(3);
parfor i=1:1
simOutput{i}=sim('mySimulation', ...
'ReturnWorkspaceOutputs', 'on', ...
'SimulationMode','normal', ...
'AbsTol','1e-6',...
'RelTol','1e-6');
end
for i=2:2
simOutput{i}=sim('mySimulation', ...
'ReturnWorkspaceOutputs', 'on', ...
'SimulationMode','normal', ...
'AbsTol','1e-6',...
'RelTol','1e-6');
end
matlabpool;
parfor i=3:3
simOutput{i}=sim('mySimulation', ...
'ReturnWorkspaceOutputs', 'on', ...
'SimulationMode','normal', ...
'AbsTol','1e-6',...
'RelTol','1e-6');
end
simOutput{1} and simOutput{2} are identical, but simOutput{3} is different. The difference is very slight, but nevertheless irritating. Might it be possible, that matlabpool has a slightly different numeric precission compared to Matlab itself?
Edric Ellis
Edric Ellis 2014 年 6 月 4 日
There are very occasional slight numerical differences caused by the fact that workers run in single-computational-thread mode. Try launching the MATLAB desktop client with the "-singleCompThread" command-line argument and comparing results.

サインインしてコメントする。

回答 (1 件)

Abhishek M
Abhishek M 2014 年 4 月 14 日

0 投票

Hi Arco, This problem arises when you aren't doing anything to save the results of the parfor loop iterations. You need introduce a new output variable and then assign your parfor output to this new variable in order to save them.

カテゴリ

ヘルプ センター および File ExchangeParallel Computing Toolbox についてさらに検索

質問済み:

2014 年 4 月 12 日

コメント済み:

2014 年 6 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by